Isolate common wait_end logic
This commit is contained in:
parent
9db698a81b
commit
1e576a35eb
@ -71,6 +71,12 @@ impl WaitQueue {
|
|||||||
}
|
}
|
||||||
count
|
count
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn wait_end(&self) -> WaitEnd {
|
||||||
|
let (wait_end, signal_end) = comm::oneshot();
|
||||||
|
self.tail.send_deferred(signal_end);
|
||||||
|
wait_end
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The building-block used to make semaphores, mutexes, and rwlocks.
|
// The building-block used to make semaphores, mutexes, and rwlocks.
|
||||||
@ -99,12 +105,9 @@ impl<Q:Send> Sem<Q> {
|
|||||||
do (**self).with |state| {
|
do (**self).with |state| {
|
||||||
state.count -= 1;
|
state.count -= 1;
|
||||||
if state.count < 0 {
|
if state.count < 0 {
|
||||||
// Create waiter nobe.
|
// Create waiter nobe, enqueue ourself, and tell
|
||||||
let (WaitEnd, SignalEnd) = comm::oneshot();
|
// outer scope we need to block.
|
||||||
// Tell outer scope we need to block.
|
waiter_nobe = Some(state.waiters.wait_end());
|
||||||
waiter_nobe = Some(WaitEnd);
|
|
||||||
// Enqueue ourself.
|
|
||||||
state.waiters.tail.send_deferred(SignalEnd);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Uncomment if you wish to test for sem races. Not valgrind-friendly.
|
// Uncomment if you wish to test for sem races. Not valgrind-friendly.
|
||||||
@ -200,10 +203,7 @@ impl<'self> Condvar<'self> {
|
|||||||
* wait() is equivalent to wait_on(0).
|
* wait() is equivalent to wait_on(0).
|
||||||
*/
|
*/
|
||||||
pub fn wait_on(&self, condvar_id: uint) {
|
pub fn wait_on(&self, condvar_id: uint) {
|
||||||
// Create waiter nobe.
|
let mut WaitEnd = None;
|
||||||
let (WaitEnd, SignalEnd) = comm::oneshot();
|
|
||||||
let mut WaitEnd = Some(WaitEnd);
|
|
||||||
let mut SignalEnd = Some(SignalEnd);
|
|
||||||
let mut out_of_bounds = None;
|
let mut out_of_bounds = None;
|
||||||
do task::unkillable {
|
do task::unkillable {
|
||||||
// Release lock, 'atomically' enqueuing ourselves in so doing.
|
// Release lock, 'atomically' enqueuing ourselves in so doing.
|
||||||
@ -215,9 +215,9 @@ impl<'self> Condvar<'self> {
|
|||||||
if state.count <= 0 {
|
if state.count <= 0 {
|
||||||
state.waiters.signal();
|
state.waiters.signal();
|
||||||
}
|
}
|
||||||
// Enqueue ourself to be woken up by a signaller.
|
// Create waiter nobe, and enqueue ourself to
|
||||||
let SignalEnd = SignalEnd.take_unwrap();
|
// be woken up by a signaller.
|
||||||
state.blocked[condvar_id].tail.send_deferred(SignalEnd);
|
WaitEnd = Some(state.blocked[condvar_id].wait_end());
|
||||||
} else {
|
} else {
|
||||||
out_of_bounds = Some(state.blocked.len());
|
out_of_bounds = Some(state.blocked.len());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user