Skip to content

Commit 5f64d5d

Browse files
committed
sync+arc - comments and attributes only
1 parent f29f308 commit 5f64d5d

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

src/libstd/arc.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ fn clone<T: const send>(rc: &arc<T>) -> arc<T> {
9797
* Mutex protected ARC (unsafe)
9898
****************************************************************************/
9999

100+
#[doc(hidden)]
100101
struct mutex_arc_inner<T: send> { lock: mutex; failed: bool; data: T; }
101102
/// An ARC with mutable data protected by a blocking mutex.
102103
struct mutex_arc<T: send> { x: SharedMutableState<mutex_arc_inner<T>>; }
@@ -182,6 +183,7 @@ impl<T: send> &mutex_arc<T> {
182183

183184
// Common code for {mutex.access,rwlock.write}{,_cond}.
184185
#[inline(always)]
186+
#[doc(hidden)]
185187
fn check_poison(is_mutex: bool, failed: bool) {
186188
if failed {
187189
if is_mutex {
@@ -192,6 +194,7 @@ fn check_poison(is_mutex: bool, failed: bool) {
192194
}
193195
}
194196
197+
#[doc(hidden)]
195198
struct poison_on_fail {
196199
failed: &mut bool;
197200
new(failed: &mut bool) { self.failed = failed; }
@@ -205,6 +208,7 @@ struct poison_on_fail {
205208
* R/W lock protected ARC
206209
****************************************************************************/
207210
211+
#[doc(hidden)]
208212
struct rw_arc_inner<T: const send> { lock: rwlock; failed: bool; data: T; }
209213
/**
210214
* A dual-mode ARC protected by a reader-writer lock. The data can be accessed
@@ -346,6 +350,7 @@ impl<T: const send> &rw_arc<T> {
346350
// Borrowck rightly complains about immutably aliasing the rwlock in order to
347351
// lock it. This wraps the unsafety, with the justification that the 'lock'
348352
// field is never overwritten; only 'failed' and 'data'.
353+
#[doc(hidden)]
349354
fn borrow_rwlock<T: const send>(state: &mut rw_arc_inner<T>) -> &rwlock {
350355
unsafe { unsafe::reinterpret_cast(&state.lock) }
351356
}

src/libstd/sync.rs

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ import unsafe::{Exclusive, exclusive};
1818
* Internals
1919
****************************************************************************/
2020

21-
// Each waiting task receives on one of these. FIXME #3125 make these oneshot.
21+
// Each waiting task receives on one of these.
22+
#[doc(hidden)]
2223
type wait_end = pipes::port_one<()>;
24+
#[doc(hidden)]
2325
type signal_end = pipes::chan_one<()>;
2426
// A doubly-ended queue of waiting tasks.
27+
#[doc(hidden)]
2528
struct waitqueue { head: pipes::port<signal_end>;
2629
tail: pipes::chan<signal_end>; }
2730

2831
// Signals one live task from the queue.
32+
#[doc(hidden)]
2933
fn signal_waitqueue(q: &waitqueue) -> bool {
3034
// The peek is mandatory to make sure recv doesn't block.
3135
if q.head.peek() {
@@ -41,6 +45,7 @@ fn signal_waitqueue(q: &waitqueue) -> bool {
4145
}
4246
}
4347

48+
#[doc(hidden)]
4449
fn broadcast_waitqueue(q: &waitqueue) -> uint {
4550
let mut count = 0;
4651
while q.head.peek() {
@@ -52,22 +57,26 @@ fn broadcast_waitqueue(q: &waitqueue) -> uint {
5257
}
5358

5459
// The building-block used to make semaphores, mutexes, and rwlocks.
60+
#[doc(hidden)]
5561
struct sem_inner<Q> {
5662
mut count: int;
5763
waiters: waitqueue;
5864
// Can be either unit or another waitqueue. Some sems shouldn't come with
5965
// a condition variable attached, others should.
6066
blocked: Q;
6167
}
68+
#[doc(hidden)]
6269
enum sem<Q: send> = Exclusive<sem_inner<Q>>;
6370

71+
#[doc(hidden)]
6472
fn new_sem<Q: send>(count: int, +q: Q) -> sem<Q> {
6573
let (wait_tail, wait_head) = pipes::stream();
6674
sem(exclusive(sem_inner {
6775
mut count: count,
6876
waiters: waitqueue { head: wait_head, tail: wait_tail },
6977
blocked: q }))
7078
}
79+
#[doc(hidden)]
7180
fn new_sem_and_signal(count: int, num_condvars: uint) -> sem<~[waitqueue]> {
7281
let mut queues = ~[];
7382
for num_condvars.times {
@@ -77,6 +86,7 @@ fn new_sem_and_signal(count: int, num_condvars: uint) -> sem<~[waitqueue]> {
7786
new_sem(count, queues)
7887
}
7988

89+
#[doc(hidden)]
8090
impl<Q: send> &sem<Q> {
8191
fn acquire() {
8292
let mut waiter_nobe = none;
@@ -112,6 +122,7 @@ impl<Q: send> &sem<Q> {
112122
}
113123
}
114124
// FIXME(#3154) move both copies of this into sem<Q>, and unify the 2 structs
125+
#[doc(hidden)]
115126
impl &sem<()> {
116127
fn access<U>(blk: fn() -> U) -> U {
117128
let mut release = none;
@@ -124,6 +135,7 @@ impl &sem<()> {
124135
blk()
125136
}
126137
}
138+
#[doc(hidden)]
127139
impl &sem<~[waitqueue]> {
128140
fn access<U>(blk: fn() -> U) -> U {
129141
let mut release = none;
@@ -138,11 +150,13 @@ impl &sem<~[waitqueue]> {
138150
}
139151

140152
// FIXME(#3136) should go inside of access()
153+
#[doc(hidden)]
141154
struct sem_release {
142155
sem: &sem<()>;
143156
new(sem: &sem<()>) { self.sem = sem; }
144157
drop { self.sem.release(); }
145158
}
159+
#[doc(hidden)]
146160
struct sem_and_signal_release {
147161
sem: &sem<~[waitqueue]>;
148162
new(sem: &sem<~[waitqueue]>) { self.sem = sem; }
@@ -153,7 +167,14 @@ struct sem_and_signal_release {
153167
struct condvar { priv sem: &sem<~[waitqueue]>; drop { } }
154168

155169
impl &condvar {
156-
/// Atomically drop the associated lock, and block until a signal is sent.
170+
/**
171+
* Atomically drop the associated lock, and block until a signal is sent.
172+
*
173+
* # Failure
174+
* A task which is killed (i.e., by linked failure with another task)
175+
* while waiting on a condition variable will wake up, fail, and unlock
176+
* the associated lock as it unwinds.
177+
*/
157178
fn wait() { self.wait_on(0) }
158179
/**
159180
* As wait(), but can specify which of multiple condition variables to
@@ -267,6 +288,7 @@ impl &condvar {
267288
// Checks whether a condvar ID was out of bounds, and fails if so, or does
268289
// something else next on success.
269290
#[inline(always)]
291+
#[doc(hidden)]
270292
fn check_cvar_bounds<U>(out_of_bounds: option<uint>, id: uint, act: &str,
271293
blk: fn() -> U) -> U {
272294
match out_of_bounds {
@@ -280,6 +302,7 @@ fn check_cvar_bounds<U>(out_of_bounds: option<uint>, id: uint, act: &str,
280302
}
281303
}
282304

305+
#[doc(hidden)]
283306
impl &sem<~[waitqueue]> {
284307
// The only other place that condvars get built is rwlock_write_mode.
285308
fn access_cond<U>(blk: fn(c: &condvar) -> U) -> U {
@@ -316,7 +339,6 @@ impl &semaphore {
316339
fn release() { (&self.sem).release() }
317340

318341
/// Run a function with ownership of one of the semaphore's resources.
319-
// FIXME(#3145): figure out whether or not this should get exported.
320342
fn access<U>(blk: fn() -> U) -> U { (&self.sem).access(blk) }
321343
}
322344

@@ -327,7 +349,10 @@ impl &semaphore {
327349
/**
328350
* A blocking, bounded-waiting, mutual exclusion lock with an associated
329351
* FIFO condition variable.
330-
* FIXME(#3145): document killability
352+
*
353+
* # Failure
354+
* A task which fails while holding a mutex will unlock the mutex as it
355+
* unwinds.
331356
*/
332357
struct mutex { priv sem: sem<~[waitqueue]>; }
333358

@@ -362,12 +387,19 @@ impl &mutex {
362387

363388
// NB: Uncyclopedia - Readers-writers_problem#The_third_readers-writers_problem
364389

390+
#[doc(hidden)]
365391
struct rwlock_inner {
366392
read_mode: bool;
367393
read_count: uint;
368394
}
369395

370-
/// A blocking, no-starvation, reader-writer lock with an associated condvar.
396+
/**
397+
* A blocking, no-starvation, reader-writer lock with an associated condvar.
398+
*
399+
* # Failure
400+
* A task which fails while holding an rwlock will unlock the rwlock as it
401+
* unwinds.
402+
*/
371403
struct rwlock {
372404
/* priv */ order_lock: semaphore;
373405
/* priv */ access_lock: sem<~[waitqueue]>;
@@ -527,6 +559,7 @@ impl &rwlock {
527559
}
528560

529561
// FIXME(#3136) should go inside of read()
562+
#[doc(hidden)]
530563
struct rwlock_release_read {
531564
lock: &rwlock;
532565
new(lock: &rwlock) { self.lock = lock; }
@@ -550,6 +583,7 @@ struct rwlock_release_read {
550583
}
551584

552585
// FIXME(#3136) should go inside of downgrade()
586+
#[doc(hidden)]
553587
struct rwlock_release_downgrade {
554588
lock: &rwlock;
555589
new(lock: &rwlock) { self.lock = lock; }
@@ -580,8 +614,7 @@ struct rwlock_release_downgrade {
580614
}
581615

582616
/// The "write permission" token used for rwlock.write_downgrade().
583-
// FIXME(#3145): make lock priv somehow
584-
struct rwlock_write_mode { lock: &rwlock; drop { } }
617+
struct rwlock_write_mode { /* priv */ lock: &rwlock; drop { } }
585618
/// The "read permission" token used for rwlock.write_downgrade().
586619
struct rwlock_read_mode { priv lock: &rwlock; drop { } }
587620

0 commit comments

Comments
 (0)