mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-15 10:07:30 +00:00
core::rt: Put a lock on the work queue
This commit is contained in:
parent
f03c9bd08c
commit
ee06ed2bfd
@ -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() )
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user