diff options
| author | Brian Anderson <banderson@mozilla.com> | 2013-05-18 01:07:16 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2013-05-20 15:20:49 -0700 |
| commit | ee06ed2bfd233b57c5989696bb723bddf6569622 (patch) | |
| tree | 31fa57585ff8908ac4daf81c6ea94c9cffccc8b6 /src/libcore/rt | |
| parent | f03c9bd08cde6c83306d91bb07c4810b8b8f13ba (diff) | |
| download | rust-ee06ed2bfd233b57c5989696bb723bddf6569622.tar.gz rust-ee06ed2bfd233b57c5989696bb723bddf6569622.zip | |
core::rt: Put a lock on the work queue
Diffstat (limited to 'src/libcore/rt')
| -rw-r--r-- | src/libcore/rt/work_queue.rs | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/src/libcore/rt/work_queue.rs b/src/libcore/rt/work_queue.rs index 7011b4ebc10..31f73cd09b5 100644 --- a/src/libcore/rt/work_queue.rs +++ b/src/libcore/rt/work_queue.rs @@ -11,39 +11,48 @@ use container::Container; use option::*; use vec::OwnedVector; +use unstable::sync::{Exclusive, exclusive}; +use cell::Cell; +use kinds::Owned; pub struct WorkQueue<T> { - priv queue: ~[T] + // XXX: Another mystery bug fixed by boxing this lock + priv queue: ~Exclusive<~[T]> } -pub impl<T> WorkQueue<T> { +pub impl<T: Owned> WorkQueue<T> { fn new() -> WorkQueue<T> { WorkQueue { - queue: ~[] + queue: ~exclusive(~[]) } } fn push(&mut self, value: T) { - self.queue.unshift(value) + let value = Cell(value); + self.queue.with(|q| q.unshift(value.take()) ); } fn pop(&mut self) -> Option<T> { - if !self.queue.is_empty() { - Some(self.queue.shift()) - } else { - None + do self.queue.with |q| { + if !q.is_empty() { + Some(q.shift()) + } else { + None + } } } fn steal(&mut self) -> Option<T> { - if !self.queue.is_empty() { - Some(self.queue.pop()) - } else { - None + do self.queue.with |q| { + if !q.is_empty() { + Some(q.pop()) + } else { + None + } } } fn is_empty(&self) -> bool { - return self.queue.is_empty(); + self.queue.with_imm(|q| q.is_empty() ) } } |
