Skip to content

Commit 09ae370

Browse files
committed
convert std::arc types to camelcase
1 parent 5dadee1 commit 09ae370

File tree

2 files changed

+79
-77
lines changed

2 files changed

+79
-77
lines changed

src/libstd/arc.rs

Lines changed: 78 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ import sync;
1313
import sync::{Mutex, mutex, mutex_with_condvars,
1414
RWlock, rwlock, rwlock_with_condvars};
1515

16-
export arc, clone, get;
17-
export condvar, mutex_arc, mutex_arc_with_condvars, unwrap_mutex_arc;
18-
export rw_arc, rw_arc_with_condvars, rw_write_mode, rw_read_mode;
16+
export ARC, arc, clone, get;
17+
export Condvar;
18+
export MutexARC, mutex_arc, mutex_arc_with_condvars, unwrap_mutex_arc;
19+
export RWARC, rw_arc, rw_arc_with_condvars, RWWriteMode, RWReadMode;
1920
export unwrap_rw_arc;
2021

2122
/// As sync::condvar, a mechanism for unlock-and-descheduling and signalling.
22-
struct condvar { is_mutex: bool; failed: &mut bool; cond: &sync::Condvar; }
23+
struct Condvar { is_mutex: bool; failed: &mut bool; cond: &sync::Condvar; }
2324

24-
impl &condvar {
25+
impl &Condvar {
2526
/// Atomically exit the associated ARC and block until a signal is sent.
2627
#[inline(always)]
2728
fn wait() { self.wait_on(0) }
@@ -69,18 +70,18 @@ impl &condvar {
6970
****************************************************************************/
7071

7172
/// An atomically reference counted wrapper for shared immutable state.
72-
struct arc<T: const send> { x: SharedMutableState<T>; }
73+
struct ARC<T: const send> { x: SharedMutableState<T>; }
7374

7475
/// Create an atomically reference counted wrapper.
75-
fn arc<T: const send>(+data: T) -> arc<T> {
76-
arc { x: unsafe { shared_mutable_state(data) } }
76+
fn arc<T: const send>(+data: T) -> ARC<T> {
77+
ARC { x: unsafe { shared_mutable_state(data) } }
7778
}
7879

7980
/**
8081
* Access the underlying data in an atomically reference counted
8182
* wrapper.
8283
*/
83-
fn get<T: const send>(rc: &arc<T>) -> &T {
84+
fn get<T: const send>(rc: &ARC<T>) -> &T {
8485
unsafe { get_shared_immutable_state(&rc.x) }
8586
}
8687

@@ -91,8 +92,8 @@ fn get<T: const send>(rc: &arc<T>) -> &T {
9192
* object. However, one of the `arc` objects can be sent to another task,
9293
* allowing them to share the underlying data.
9394
*/
94-
fn clone<T: const send>(rc: &arc<T>) -> arc<T> {
95-
arc { x: unsafe { clone_shared_mutable_state(&rc.x) } }
95+
fn clone<T: const send>(rc: &ARC<T>) -> ARC<T> {
96+
ARC { x: unsafe { clone_shared_mutable_state(&rc.x) } }
9697
}
9798

9899
/**
@@ -104,8 +105,8 @@ fn clone<T: const send>(rc: &arc<T>) -> arc<T> {
104105
* unwrap from a task that holds another reference to the same ARC; it is
105106
* guaranteed to deadlock.
106107
*/
107-
fn unwrap<T: const send>(+rc: arc<T>) -> T {
108-
let arc { x: x } = rc;
108+
fn unwrap<T: const send>(+rc: ARC<T>) -> T {
109+
let ARC { x: x } = rc;
109110
unsafe { unwrap_shared_mutable_state(x) }
110111
}
111112

@@ -114,32 +115,32 @@ fn unwrap<T: const send>(+rc: arc<T>) -> T {
114115
****************************************************************************/
115116

116117
#[doc(hidden)]
117-
struct mutex_arc_inner<T: send> { lock: Mutex; failed: bool; data: T; }
118+
struct MutexARCInner<T: send> { lock: Mutex; failed: bool; data: T; }
118119
/// An ARC with mutable data protected by a blocking mutex.
119-
struct mutex_arc<T: send> { x: SharedMutableState<mutex_arc_inner<T>>; }
120+
struct MutexARC<T: send> { x: SharedMutableState<MutexARCInner<T>>; }
120121

121122
/// Create a mutex-protected ARC with the supplied data.
122-
fn mutex_arc<T: send>(+user_data: T) -> mutex_arc<T> {
123+
fn mutex_arc<T: send>(+user_data: T) -> MutexARC<T> {
123124
mutex_arc_with_condvars(user_data, 1)
124125
}
125126
/**
126127
* Create a mutex-protected ARC with the supplied data and a specified number
127128
* of condvars (as sync::mutex_with_condvars).
128129
*/
129130
fn mutex_arc_with_condvars<T: send>(+user_data: T,
130-
num_condvars: uint) -> mutex_arc<T> {
131+
num_condvars: uint) -> MutexARC<T> {
131132
let data =
132-
mutex_arc_inner { lock: mutex_with_condvars(num_condvars),
133+
MutexARCInner { lock: mutex_with_condvars(num_condvars),
133134
failed: false, data: user_data };
134-
mutex_arc { x: unsafe { shared_mutable_state(data) } }
135+
MutexARC { x: unsafe { shared_mutable_state(data) } }
135136
}
136137

137-
impl<T: send> &mutex_arc<T> {
138+
impl<T: send> &MutexARC<T> {
138139
/// Duplicate a mutex-protected ARC, as arc::clone.
139-
fn clone() -> mutex_arc<T> {
140+
fn clone() -> MutexARC<T> {
140141
// NB: Cloning the underlying mutex is not necessary. Its reference
141142
// count would be exactly the same as the shared state's.
142-
mutex_arc { x: unsafe { clone_shared_mutable_state(&self.x) } }
143+
MutexARC { x: unsafe { clone_shared_mutable_state(&self.x) } }
143144
}
144145

145146
/**
@@ -172,19 +173,19 @@ impl<T: send> &mutex_arc<T> {
172173
// unsafe. See borrow_rwlock, far below.
173174
do (&state.lock).lock {
174175
check_poison(true, state.failed);
175-
let _z = poison_on_fail(&mut state.failed);
176+
let _z = PoisonOnFail(&mut state.failed);
176177
blk(&mut state.data)
177178
}
178179
}
179180
/// As access(), but with a condvar, as sync::mutex.lock_cond().
180181
#[inline(always)]
181-
unsafe fn access_cond<U>(blk: fn(x: &x/mut T, c: &c/condvar) -> U) -> U {
182+
unsafe fn access_cond<U>(blk: fn(x: &x/mut T, c: &c/Condvar) -> U) -> U {
182183
let state = unsafe { get_shared_mutable_state(&self.x) };
183184
do (&state.lock).lock_cond |cond| {
184185
check_poison(true, state.failed);
185-
let _z = poison_on_fail(&mut state.failed);
186+
let _z = PoisonOnFail(&mut state.failed);
186187
blk(&mut state.data,
187-
&condvar { is_mutex: true, failed: &mut state.failed,
188+
&Condvar { is_mutex: true, failed: &mut state.failed,
188189
cond: cond })
189190
}
190191
}
@@ -197,12 +198,12 @@ impl<T: send> &mutex_arc<T> {
197198
* Will additionally fail if another task has failed while accessing the arc.
198199
*/
199200
// FIXME(#2585) make this a by-move method on the arc
200-
fn unwrap_mutex_arc<T: send>(+arc: mutex_arc<T>) -> T {
201-
let mutex_arc { x: x } = arc;
201+
fn unwrap_mutex_arc<T: send>(+arc: MutexARC<T>) -> T {
202+
let MutexARC { x: x } = arc;
202203
let inner = unsafe { unwrap_shared_mutable_state(x) };
203-
let mutex_arc_inner { failed: failed, data: data, _ } = inner;
204+
let MutexARCInner { failed: failed, data: data, _ } = inner;
204205
if failed {
205-
fail ~"Can't unwrap poisoned mutex_arc - another task failed inside!"
206+
fail ~"Can't unwrap poisoned MutexARC - another task failed inside!"
206207
}
207208
data
208209
}
@@ -213,15 +214,15 @@ fn unwrap_mutex_arc<T: send>(+arc: mutex_arc<T>) -> T {
213214
fn check_poison(is_mutex: bool, failed: bool) {
214215
if failed {
215216
if is_mutex {
216-
fail ~"Poisoned mutex_arc - another task failed inside!";
217+
fail ~"Poisoned MutexARC - another task failed inside!";
217218
} else {
218219
fail ~"Poisoned rw_arc - another task failed inside!";
219220
}
220221
}
221222
}
222223
223224
#[doc(hidden)]
224-
struct poison_on_fail {
225+
struct PoisonOnFail {
225226
failed: &mut bool;
226227
new(failed: &mut bool) { self.failed = failed; }
227228
drop {
@@ -235,39 +236,39 @@ struct poison_on_fail {
235236
****************************************************************************/
236237
237238
#[doc(hidden)]
238-
struct rw_arc_inner<T: const send> { lock: RWlock; failed: bool; data: T; }
239+
struct RWARCInner<T: const send> { lock: RWlock; failed: bool; data: T; }
239240
/**
240241
* A dual-mode ARC protected by a reader-writer lock. The data can be accessed
241242
* mutably or immutably, and immutably-accessing tasks may run concurrently.
242243
*
243244
* Unlike mutex_arcs, rw_arcs are safe, because they cannot be nested.
244245
*/
245-
struct rw_arc<T: const send> {
246-
x: SharedMutableState<rw_arc_inner<T>>;
246+
struct RWARC<T: const send> {
247+
x: SharedMutableState<RWARCInner<T>>;
247248
mut cant_nest: ();
248249
}
249250
250251
/// Create a reader/writer ARC with the supplied data.
251-
fn rw_arc<T: const send>(+user_data: T) -> rw_arc<T> {
252+
fn rw_arc<T: const send>(+user_data: T) -> RWARC<T> {
252253
rw_arc_with_condvars(user_data, 1)
253254
}
254255
/**
255256
* Create a reader/writer ARC with the supplied data and a specified number
256257
* of condvars (as sync::rwlock_with_condvars).
257258
*/
258259
fn rw_arc_with_condvars<T: const send>(+user_data: T,
259-
num_condvars: uint) -> rw_arc<T> {
260+
num_condvars: uint) -> RWARC<T> {
260261
let data =
261-
rw_arc_inner { lock: rwlock_with_condvars(num_condvars),
262-
failed: false, data: user_data };
263-
rw_arc { x: unsafe { shared_mutable_state(data) }, cant_nest: () }
262+
RWARCInner { lock: rwlock_with_condvars(num_condvars),
263+
failed: false, data: user_data };
264+
RWARC { x: unsafe { shared_mutable_state(data) }, cant_nest: () }
264265
}
265266
266-
impl<T: const send> &rw_arc<T> {
267+
impl<T: const send> &RWARC<T> {
267268
/// Duplicate a rwlock-protected ARC, as arc::clone.
268-
fn clone() -> rw_arc<T> {
269-
rw_arc { x: unsafe { clone_shared_mutable_state(&self.x) },
270-
cant_nest: () }
269+
fn clone() -> RWARC<T> {
270+
RWARC { x: unsafe { clone_shared_mutable_state(&self.x) },
271+
cant_nest: () }
271272
}
272273
273274
/**
@@ -277,27 +278,27 @@ impl<T: const send> &rw_arc<T> {
277278
* # Failure
278279
*
279280
* Failing while inside the ARC will unlock the ARC while unwinding, so
280-
* that other tasks won't block forever. As mutex_arc.access, it will also
281+
* that other tasks won't block forever. As MutexARC.access, it will also
281282
* poison the ARC, so subsequent readers and writers will both also fail.
282283
*/
283284
#[inline(always)]
284285
fn write<U>(blk: fn(x: &mut T) -> U) -> U {
285286
let state = unsafe { get_shared_mutable_state(&self.x) };
286287
do borrow_rwlock(state).write {
287288
check_poison(false, state.failed);
288-
let _z = poison_on_fail(&mut state.failed);
289+
let _z = PoisonOnFail(&mut state.failed);
289290
blk(&mut state.data)
290291
}
291292
}
292293
/// As write(), but with a condvar, as sync::rwlock.write_cond().
293294
#[inline(always)]
294-
fn write_cond<U>(blk: fn(x: &x/mut T, c: &c/condvar) -> U) -> U {
295+
fn write_cond<U>(blk: fn(x: &x/mut T, c: &c/Condvar) -> U) -> U {
295296
let state = unsafe { get_shared_mutable_state(&self.x) };
296297
do borrow_rwlock(state).write_cond |cond| {
297298
check_poison(false, state.failed);
298-
let _z = poison_on_fail(&mut state.failed);
299+
let _z = PoisonOnFail(&mut state.failed);
299300
blk(&mut state.data,
300-
&condvar { is_mutex: false, failed: &mut state.failed,
301+
&Condvar { is_mutex: false, failed: &mut state.failed,
301302
cond: cond })
302303
}
303304
}
@@ -320,9 +321,9 @@ impl<T: const send> &rw_arc<T> {
320321
321322
/**
322323
* As write(), but with the ability to atomically 'downgrade' the lock.
323-
* See sync::rwlock.write_downgrade(). The rw_write_mode token must be
324-
* used to obtain the &mut T, and can be transformed into a rw_read_mode
325-
* token by calling downgrade(), after which a &T can be obtained instead.
324+
* See sync::rwlock.write_downgrade(). The RWWriteMode token must be used
325+
* to obtain the &mut T, and can be transformed into a RWReadMode token by
326+
* calling downgrade(), after which a &T can be obtained instead.
326327
* ~~~
327328
* do arc.write_downgrade |write_mode| {
328329
* do (&write_mode).write_cond |state, condvar| {
@@ -335,20 +336,20 @@ impl<T: const send> &rw_arc<T> {
335336
* }
336337
* ~~~
337338
*/
338-
fn write_downgrade<U>(blk: fn(+rw_write_mode<T>) -> U) -> U {
339+
fn write_downgrade<U>(blk: fn(+RWWriteMode<T>) -> U) -> U {
339340
let state = unsafe { get_shared_mutable_state(&self.x) };
340341
do borrow_rwlock(state).write_downgrade |write_mode| {
341342
check_poison(false, state.failed);
342-
blk(rw_write_mode((&mut state.data, write_mode,
343-
poison_on_fail(&mut state.failed))))
343+
blk(RWWriteMode((&mut state.data, write_mode,
344+
PoisonOnFail(&mut state.failed))))
344345
}
345346
}
346347
347348
/// To be called inside of the write_downgrade block.
348-
fn downgrade(+token: rw_write_mode/&a<T>) -> rw_read_mode/&a<T> {
349+
fn downgrade(+token: RWWriteMode/&a<T>) -> RWReadMode/&a<T> {
349350
// The rwlock should assert that the token belongs to us for us.
350351
let state = unsafe { get_shared_immutable_state(&self.x) };
351-
let rw_write_mode((data, t, _poison)) = token;
352+
let RWWriteMode((data, t, _poison)) = token;
352353
// Let readers in
353354
let new_token = (&state.lock).downgrade(t);
354355
// Whatever region the input reference had, it will be safe to use
@@ -358,7 +359,7 @@ impl<T: const send> &rw_arc<T> {
358359
// Downgrade ensured the token belonged to us. Just a sanity check.
359360
assert ptr::ref_eq(&state.data, new_data);
360361
// Produce new token
361-
rw_read_mode((new_data, new_token))
362+
RWReadMode((new_data, new_token))
362363
}
363364
}
364365
@@ -370,12 +371,12 @@ impl<T: const send> &rw_arc<T> {
370371
* in write mode.
371372
*/
372373
// FIXME(#2585) make this a by-move method on the arc
373-
fn unwrap_rw_arc<T: const send>(+arc: rw_arc<T>) -> T {
374-
let rw_arc { x: x, _ } = arc;
374+
fn unwrap_rw_arc<T: const send>(+arc: RWARC<T>) -> T {
375+
let RWARC { x: x, _ } = arc;
375376
let inner = unsafe { unwrap_shared_mutable_state(x) };
376-
let rw_arc_inner { failed: failed, data: data, _ } = inner;
377+
let RWARCInner { failed: failed, data: data, _ } = inner;
377378
if failed {
378-
fail ~"Can't unwrap poisoned rw_arc - another task failed inside!"
379+
fail ~"Can't unwrap poisoned RWARC - another task failed inside!"
379380
}
380381
data
381382
}
@@ -384,35 +385,35 @@ fn unwrap_rw_arc<T: const send>(+arc: rw_arc<T>) -> T {
384385
// lock it. This wraps the unsafety, with the justification that the 'lock'
385386
// field is never overwritten; only 'failed' and 'data'.
386387
#[doc(hidden)]
387-
fn borrow_rwlock<T: const send>(state: &r/mut rw_arc_inner<T>) -> &r/RWlock {
388+
fn borrow_rwlock<T: const send>(state: &r/mut RWARCInner<T>) -> &r/RWlock {
388389
unsafe { unsafe::transmute_immut(&mut state.lock) }
389390
}
390391
391392
// FIXME (#3154) ice with struct/&<T> prevents these from being structs.
392393
393-
/// The "write permission" token used for rw_arc.write_downgrade().
394-
enum rw_write_mode<T: const send> =
395-
(&mut T, sync::RWlockWriteMode, poison_on_fail);
396-
/// The "read permission" token used for rw_arc.write_downgrade().
397-
enum rw_read_mode<T:const send> = (&T, sync::RWlockReadMode);
394+
/// The "write permission" token used for RWARC.write_downgrade().
395+
enum RWWriteMode<T: const send> =
396+
(&mut T, sync::RWlockWriteMode, PoisonOnFail);
397+
/// The "read permission" token used for RWARC.write_downgrade().
398+
enum RWReadMode<T:const send> = (&T, sync::RWlockReadMode);
398399

399-
impl<T: const send> &rw_write_mode<T> {
400-
/// Access the pre-downgrade rw_arc in write mode.
400+
impl<T: const send> &RWWriteMode<T> {
401+
/// Access the pre-downgrade RWARC in write mode.
401402
fn write<U>(blk: fn(x: &mut T) -> U) -> U {
402403
match *self {
403-
rw_write_mode((data, ref token, _)) => {
404+
RWWriteMode((data, ref token, _)) => {
404405
do token.write {
405406
blk(data)
406407
}
407408
}
408409
}
409410
}
410-
/// Access the pre-downgrade rw_arc in write mode with a condvar.
411-
fn write_cond<U>(blk: fn(x: &x/mut T, c: &c/condvar) -> U) -> U {
411+
/// Access the pre-downgrade RWARC in write mode with a condvar.
412+
fn write_cond<U>(blk: fn(x: &x/mut T, c: &c/Condvar) -> U) -> U {
412413
match *self {
413-
rw_write_mode((data, ref token, ref poison)) => {
414+
RWWriteMode((data, ref token, ref poison)) => {
414415
do token.write_cond |cond| {
415-
let cvar = condvar {
416+
let cvar = Condvar {
416417
is_mutex: false, failed: poison.failed,
417418
cond: cond };
418419
blk(data, &cvar)
@@ -422,11 +423,11 @@ impl<T: const send> &rw_write_mode<T> {
422423
}
423424
}
424425

425-
impl<T: const send> &rw_read_mode<T> {
426+
impl<T: const send> &RWReadMode<T> {
426427
/// Access the post-downgrade rwlock in read mode.
427428
fn read<U>(blk: fn(x: &T) -> U) -> U {
428429
match *self {
429-
rw_read_mode((data, ref token)) => {
430+
RWReadMode((data, ref token)) => {
430431
do token.read { blk(data) }
431432
}
432433
}

src/libstd/std.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ mod cell;
5252

5353
#[warn(non_camel_case_types)]
5454
mod sync;
55+
#[warn(non_camel_case_types)]
5556
mod arc;
5657
mod comm;
5758

0 commit comments

Comments
 (0)