Skip to content

Commit 2cc1c3e

Browse files
committed
---
yaml --- r: 29843 b: refs/heads/incoming c: f29f308 h: refs/heads/master i: 29841: e2f3c73 29839: 207d73b v: v3
1 parent b9f755e commit 2cc1c3e

File tree

3 files changed

+57
-16
lines changed

3 files changed

+57
-16
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: d1fc7368c858a8280f2463e81e074a2c699b0819
9+
refs/heads/incoming: f29f308c1c7c611cda6e1fc8a56179296868d144
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/libstd/arc.rs

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,55 @@ import unsafe::{SharedMutableState,
1010
shared_mutable_state, clone_shared_mutable_state,
1111
get_shared_mutable_state, get_shared_immutable_state};
1212
import sync;
13-
import sync::{mutex, rwlock};
13+
import sync::{mutex, mutex_with_condvars, rwlock, rwlock_with_condvars};
1414

1515
export arc, clone, get;
16-
export condvar, mutex_arc, rw_arc, rw_write_mode, rw_read_mode;
16+
export condvar, mutex_arc, mutex_arc_with_condvars;
17+
export rw_arc, rw_arc_with_condvars, rw_write_mode, rw_read_mode;
1718

1819
/// As sync::condvar, a mechanism for unlock-and-descheduling and signalling.
1920
struct condvar { is_mutex: bool; failed: &mut bool; cond: &sync::condvar; }
2021

2122
impl &condvar {
2223
/// Atomically exit the associated ARC and block until a signal is sent.
23-
fn wait() {
24+
#[inline(always)]
25+
fn wait() { self.wait_on(0) }
26+
/**
27+
* Atomically exit the associated ARC and block on a specified condvar
28+
* until a signal is sent on that same condvar (as sync::cond.wait_on).
29+
*
30+
* wait() is equivalent to wait_on(0).
31+
*/
32+
#[inline(always)]
33+
fn wait_on(condvar_id: uint) {
2434
assert !*self.failed;
25-
self.cond.wait();
35+
self.cond.wait_on(condvar_id);
2636
// This is why we need to wrap sync::condvar.
2737
check_poison(self.is_mutex, *self.failed);
2838
}
2939
/// Wake up a blocked task. Returns false if there was no blocked task.
30-
fn signal() -> bool {
40+
#[inline(always)]
41+
fn signal() -> bool { self.signal_on(0) }
42+
/**
43+
* Wake up a blocked task on a specified condvar (as
44+
* sync::cond.signal_on). Returns false if there was no blocked task.
45+
*/
46+
#[inline(always)]
47+
fn signal_on(condvar_id: uint) -> bool {
3148
assert !*self.failed;
32-
self.cond.signal()
49+
self.cond.signal_on(condvar_id)
3350
}
3451
/// Wake up all blocked tasks. Returns the number of tasks woken.
35-
fn broadcast() -> uint {
52+
#[inline(always)]
53+
fn broadcast() -> uint { self.broadcast_on(0) }
54+
/**
55+
* Wake up all blocked tasks on a specified condvar (as
56+
* sync::cond.broadcast_on). Returns Returns the number of tasks woken.
57+
*/
58+
#[inline(always)]
59+
fn broadcast_on(condvar_id: uint) -> uint {
3660
assert !*self.failed;
37-
self.cond.broadcast()
61+
self.cond.broadcast_on(condvar_id)
3862
}
3963
}
4064

@@ -79,9 +103,17 @@ struct mutex_arc<T: send> { x: SharedMutableState<mutex_arc_inner<T>>; }
79103

80104
/// Create a mutex-protected ARC with the supplied data.
81105
fn mutex_arc<T: send>(+user_data: T) -> mutex_arc<T> {
82-
let data = mutex_arc_inner {
83-
lock: mutex(), failed: false, data: user_data
84-
};
106+
mutex_arc_with_condvars(user_data, 1)
107+
}
108+
/**
109+
* Create a mutex-protected ARC with the supplied data and a specified number
110+
* of condvars (as sync::mutex_with_condvars).
111+
*/
112+
fn mutex_arc_with_condvars<T: send>(+user_data: T,
113+
num_condvars: uint) -> mutex_arc<T> {
114+
let data =
115+
mutex_arc_inner { lock: mutex_with_condvars(num_condvars),
116+
failed: false, data: user_data };
85117
mutex_arc { x: unsafe { shared_mutable_state(data) } }
86118
}
87119

@@ -187,9 +219,17 @@ struct rw_arc<T: const send> {
187219
188220
/// Create a reader/writer ARC with the supplied data.
189221
fn rw_arc<T: const send>(+user_data: T) -> rw_arc<T> {
190-
let data = rw_arc_inner {
191-
lock: rwlock(), failed: false, data: user_data
192-
};
222+
rw_arc_with_condvars(user_data, 1)
223+
}
224+
/**
225+
* Create a reader/writer ARC with the supplied data and a specified number
226+
* of condvars (as sync::rwlock_with_condvars).
227+
*/
228+
fn rw_arc_with_condvars<T: const send>(+user_data: T,
229+
num_condvars: uint) -> rw_arc<T> {
230+
let data =
231+
rw_arc_inner { lock: rwlock_with_condvars(num_condvars),
232+
failed: false, data: user_data };
193233
rw_arc { x: unsafe { shared_mutable_state(data) }, cant_nest: () }
194234
}
195235

branches/incoming/src/libstd/sync.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
* in std.
99
*/
1010

11-
export condvar, semaphore, mutex, rwlock, rwlock_write_mode, rwlock_read_mode;
11+
export condvar, semaphore, mutex, mutex_with_condvars;
12+
export rwlock, rwlock_with_condvars, rwlock_write_mode, rwlock_read_mode;
1213

1314
// FIXME (#3119) This shouldn't be a thing exported from core.
1415
import unsafe::{Exclusive, exclusive};

0 commit comments

Comments
 (0)