@@ -13,15 +13,16 @@ import sync;
13
13
import sync:: { Mutex , mutex, mutex_with_condvars,
14
14
RWlock , rwlock, rwlock_with_condvars} ;
15
15
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 ;
19
20
export unwrap_rw_arc;
20
21
21
22
/// 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 ; }
23
24
24
- impl & condvar {
25
+ impl & Condvar {
25
26
/// Atomically exit the associated ARC and block until a signal is sent.
26
27
#[ inline( always) ]
27
28
fn wait ( ) { self . wait_on ( 0 ) }
@@ -69,18 +70,18 @@ impl &condvar {
69
70
****************************************************************************/
70
71
71
72
/// 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 > ; }
73
74
74
75
/// 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) } }
77
78
}
78
79
79
80
/**
80
81
* Access the underlying data in an atomically reference counted
81
82
* wrapper.
82
83
*/
83
- fn get < T : const send > ( rc : & arc < T > ) -> & T {
84
+ fn get < T : const send > ( rc : & ARC < T > ) -> & T {
84
85
unsafe { get_shared_immutable_state ( & rc. x ) }
85
86
}
86
87
@@ -91,8 +92,8 @@ fn get<T: const send>(rc: &arc<T>) -> &T {
91
92
* object. However, one of the `arc` objects can be sent to another task,
92
93
* allowing them to share the underlying data.
93
94
*/
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 ) } }
96
97
}
97
98
98
99
/**
@@ -104,8 +105,8 @@ fn clone<T: const send>(rc: &arc<T>) -> arc<T> {
104
105
* unwrap from a task that holds another reference to the same ARC; it is
105
106
* guaranteed to deadlock.
106
107
*/
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;
109
110
unsafe { unwrap_shared_mutable_state ( x) }
110
111
}
111
112
@@ -114,32 +115,32 @@ fn unwrap<T: const send>(+rc: arc<T>) -> T {
114
115
****************************************************************************/
115
116
116
117
#[ 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 ; }
118
119
/// 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 > > ; }
120
121
121
122
/// 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 > {
123
124
mutex_arc_with_condvars ( user_data, 1 )
124
125
}
125
126
/**
126
127
* Create a mutex-protected ARC with the supplied data and a specified number
127
128
* of condvars (as sync::mutex_with_condvars).
128
129
*/
129
130
fn mutex_arc_with_condvars < T : send > ( +user_data : T ,
130
- num_condvars : uint ) -> mutex_arc < T > {
131
+ num_condvars : uint ) -> MutexARC < T > {
131
132
let data =
132
- mutex_arc_inner { lock : mutex_with_condvars ( num_condvars) ,
133
+ MutexARCInner { lock : mutex_with_condvars ( num_condvars) ,
133
134
failed : false , data : user_data } ;
134
- mutex_arc { x : unsafe { shared_mutable_state ( data) } }
135
+ MutexARC { x : unsafe { shared_mutable_state ( data) } }
135
136
}
136
137
137
- impl < T : send > & mutex_arc < T > {
138
+ impl < T : send > & MutexARC < T > {
138
139
/// Duplicate a mutex-protected ARC, as arc::clone.
139
- fn clone ( ) -> mutex_arc < T > {
140
+ fn clone ( ) -> MutexARC < T > {
140
141
// NB: Cloning the underlying mutex is not necessary. Its reference
141
142
// 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 ) } }
143
144
}
144
145
145
146
/**
@@ -172,19 +173,19 @@ impl<T: send> &mutex_arc<T> {
172
173
// unsafe. See borrow_rwlock, far below.
173
174
do ( & state. lock ) . lock {
174
175
check_poison ( true , state. failed ) ;
175
- let _z = poison_on_fail ( & mut state. failed ) ;
176
+ let _z = PoisonOnFail ( & mut state. failed ) ;
176
177
blk ( & mut state. data )
177
178
}
178
179
}
179
180
/// As access(), but with a condvar, as sync::mutex.lock_cond().
180
181
#[ 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 {
182
183
let state = unsafe { get_shared_mutable_state ( & self . x ) } ;
183
184
do ( & state. lock ) . lock_cond |cond| {
184
185
check_poison ( true , state. failed ) ;
185
- let _z = poison_on_fail ( & mut state. failed ) ;
186
+ let _z = PoisonOnFail ( & mut state. failed ) ;
186
187
blk ( & mut state. data ,
187
- & condvar { is_mutex : true , failed : & mut state. failed ,
188
+ & Condvar { is_mutex : true , failed : & mut state. failed ,
188
189
cond : cond } )
189
190
}
190
191
}
@@ -197,12 +198,12 @@ impl<T: send> &mutex_arc<T> {
197
198
* Will additionally fail if another task has failed while accessing the arc.
198
199
*/
199
200
// 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;
202
203
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;
204
205
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!"
206
207
}
207
208
data
208
209
}
@@ -213,15 +214,15 @@ fn unwrap_mutex_arc<T: send>(+arc: mutex_arc<T>) -> T {
213
214
fn check_poison(is_mutex: bool, failed: bool) {
214
215
if failed {
215
216
if is_mutex {
216
- fail ~" Poisoned mutex_arc - another task failed inside!";
217
+ fail ~" Poisoned MutexARC - another task failed inside!";
217
218
} else {
218
219
fail ~" Poisoned rw_arc - another task failed inside!";
219
220
}
220
221
}
221
222
}
222
223
223
224
#[doc(hidden)]
224
- struct poison_on_fail {
225
+ struct PoisonOnFail {
225
226
failed: &mut bool;
226
227
new(failed: &mut bool) { self.failed = failed; }
227
228
drop {
@@ -235,39 +236,39 @@ struct poison_on_fail {
235
236
****************************************************************************/
236
237
237
238
#[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; }
239
240
/**
240
241
* A dual-mode ARC protected by a reader-writer lock. The data can be accessed
241
242
* mutably or immutably, and immutably-accessing tasks may run concurrently.
242
243
*
243
244
* Unlike mutex_arcs, rw_arcs are safe, because they cannot be nested.
244
245
*/
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>>;
247
248
mut cant_nest: ();
248
249
}
249
250
250
251
/// 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> {
252
253
rw_arc_with_condvars(user_data, 1)
253
254
}
254
255
/**
255
256
* Create a reader/writer ARC with the supplied data and a specified number
256
257
* of condvars (as sync::rwlock_with_condvars).
257
258
*/
258
259
fn rw_arc_with_condvars<T: const send>(+user_data: T,
259
- num_condvars: uint) -> rw_arc <T> {
260
+ num_condvars: uint) -> RWARC <T> {
260
261
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: () }
264
265
}
265
266
266
- impl<T: const send> &rw_arc <T> {
267
+ impl<T: const send> &RWARC <T> {
267
268
/// 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: () }
271
272
}
272
273
273
274
/**
@@ -277,27 +278,27 @@ impl<T: const send> &rw_arc<T> {
277
278
* # Failure
278
279
*
279
280
* 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
281
282
* poison the ARC, so subsequent readers and writers will both also fail.
282
283
*/
283
284
#[inline(always)]
284
285
fn write<U>(blk: fn(x: &mut T) -> U) -> U {
285
286
let state = unsafe { get_shared_mutable_state(&self.x) };
286
287
do borrow_rwlock(state).write {
287
288
check_poison(false, state.failed);
288
- let _z = poison_on_fail (&mut state.failed);
289
+ let _z = PoisonOnFail (&mut state.failed);
289
290
blk(&mut state.data)
290
291
}
291
292
}
292
293
/// As write(), but with a condvar, as sync::rwlock.write_cond().
293
294
#[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 {
295
296
let state = unsafe { get_shared_mutable_state(&self.x) };
296
297
do borrow_rwlock(state).write_cond |cond| {
297
298
check_poison(false, state.failed);
298
- let _z = poison_on_fail (&mut state.failed);
299
+ let _z = PoisonOnFail (&mut state.failed);
299
300
blk(&mut state.data,
300
- &condvar { is_mutex: false, failed: &mut state.failed,
301
+ &Condvar { is_mutex: false, failed: &mut state.failed,
301
302
cond: cond })
302
303
}
303
304
}
@@ -320,9 +321,9 @@ impl<T: const send> &rw_arc<T> {
320
321
321
322
/**
322
323
* 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.
326
327
* ~~~
327
328
* do arc.write_downgrade |write_mode| {
328
329
* do (&write_mode).write_cond |state, condvar| {
@@ -335,20 +336,20 @@ impl<T: const send> &rw_arc<T> {
335
336
* }
336
337
* ~~~
337
338
*/
338
- fn write_downgrade<U>(blk: fn(+rw_write_mode <T>) -> U) -> U {
339
+ fn write_downgrade<U>(blk: fn(+RWWriteMode <T>) -> U) -> U {
339
340
let state = unsafe { get_shared_mutable_state(&self.x) };
340
341
do borrow_rwlock(state).write_downgrade |write_mode| {
341
342
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))))
344
345
}
345
346
}
346
347
347
348
/// 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> {
349
350
// The rwlock should assert that the token belongs to us for us.
350
351
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;
352
353
// Let readers in
353
354
let new_token = (&state.lock).downgrade(t);
354
355
// Whatever region the input reference had, it will be safe to use
@@ -358,7 +359,7 @@ impl<T: const send> &rw_arc<T> {
358
359
// Downgrade ensured the token belonged to us. Just a sanity check.
359
360
assert ptr::ref_eq(&state.data, new_data);
360
361
// Produce new token
361
- rw_read_mode ((new_data, new_token))
362
+ RWReadMode ((new_data, new_token))
362
363
}
363
364
}
364
365
@@ -370,12 +371,12 @@ impl<T: const send> &rw_arc<T> {
370
371
* in write mode.
371
372
*/
372
373
// 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;
375
376
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;
377
378
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!"
379
380
}
380
381
data
381
382
}
@@ -384,35 +385,35 @@ fn unwrap_rw_arc<T: const send>(+arc: rw_arc<T>) -> T {
384
385
// lock it. This wraps the unsafety, with the justification that the 'lock'
385
386
// field is never overwritten; only 'failed' and 'data'.
386
387
#[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 {
388
389
unsafe { unsafe::transmute_immut(&mut state.lock) }
389
390
}
390
391
391
392
// FIXME (#3154) ice with struct/&<T> prevents these from being structs.
392
393
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 ) ;
398
399
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.
401
402
fn write < U > ( blk : fn ( x : & mut T ) -> U ) -> U {
402
403
match * self {
403
- rw_write_mode ( ( data, ref token, _) ) => {
404
+ RWWriteMode ( ( data, ref token, _) ) => {
404
405
do token. write {
405
406
blk ( data)
406
407
}
407
408
}
408
409
}
409
410
}
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 {
412
413
match * self {
413
- rw_write_mode ( ( data, ref token, ref poison) ) => {
414
+ RWWriteMode ( ( data, ref token, ref poison) ) => {
414
415
do token. write_cond |cond| {
415
- let cvar = condvar {
416
+ let cvar = Condvar {
416
417
is_mutex : false , failed : poison. failed ,
417
418
cond : cond } ;
418
419
blk ( data, & cvar)
@@ -422,11 +423,11 @@ impl<T: const send> &rw_write_mode<T> {
422
423
}
423
424
}
424
425
425
- impl < T : const send > & rw_read_mode < T > {
426
+ impl < T : const send > & RWReadMode < T > {
426
427
/// Access the post-downgrade rwlock in read mode.
427
428
fn read < U > ( blk : fn ( x : & T ) -> U ) -> U {
428
429
match * self {
429
- rw_read_mode ( ( data, ref token) ) => {
430
+ RWReadMode ( ( data, ref token) ) => {
430
431
do token. read { blk ( data) }
431
432
}
432
433
}
0 commit comments