-
Notifications
You must be signed in to change notification settings - Fork 560
mock up breadth_first and spawn_tail
#360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
7fa963b
cd6cab3
df7759a
9d84c5e
e1b7243
7b25a39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,6 +112,7 @@ impl<'a> Drop for Terminator<'a> { | |
| impl Registry { | ||
| pub fn new(mut configuration: Configuration) -> Result<Arc<Registry>, Box<Error>> { | ||
| let n_threads = configuration.get_num_threads(); | ||
| let breadth_first = configuration.get_breadth_first(); | ||
|
|
||
| let (inj_worker, inj_stealer) = deque::new(); | ||
| let (workers, stealers): (Vec<_>, Vec<_>) = (0..n_threads).map(|_| deque::new()).unzip(); | ||
|
|
@@ -141,7 +142,7 @@ impl Registry { | |
| if let Some(stack_size) = configuration.get_stack_size() { | ||
| b = b.stack_size(stack_size); | ||
| } | ||
| try!(b.spawn(move || unsafe { main_loop(worker, registry, index) })); | ||
| try!(b.spawn(move || unsafe { main_loop(worker, registry, index, breadth_first) })); | ||
| } | ||
|
|
||
| // Returning normally now, without termination. | ||
|
|
@@ -349,9 +350,17 @@ impl ThreadInfo { | |
| /// WorkerThread identifiers | ||
|
|
||
| pub struct WorkerThread { | ||
| /// the "worker" half of our local deque | ||
| worker: Worker<JobRef>, | ||
|
|
||
| /// a "stealer" half of our local deque; used in BFS mode | ||
| stealer: Stealer<JobRef>, | ||
|
|
||
| index: usize, | ||
|
|
||
| /// are these workers configured to steal breadth-first or not? | ||
| breadth_first: bool, | ||
|
|
||
| /// A weak random number generator. | ||
| rng: UnsafeCell<rand::XorShiftRng>, | ||
|
|
||
|
|
@@ -403,11 +412,27 @@ impl WorkerThread { | |
| self.registry.sleep.tickle(self.index); | ||
| } | ||
|
|
||
| /// Pop `job` from top of stack, returning `false` if it has been | ||
| /// stolen. | ||
| #[inline] | ||
| pub unsafe fn pop(&self) -> Option<JobRef> { | ||
| self.worker.pop() | ||
| pub fn local_deque_is_empty(&self) -> bool { | ||
| self.worker.len() == 0 | ||
| } | ||
|
|
||
| #[inline] | ||
| pub fn breadth_first(&self) -> bool { | ||
| self.breadth_first | ||
| } | ||
|
|
||
| /// Attempts to obtain a "local" job -- typically this means | ||
| /// popping from the top of the stack, though if we are configured | ||
| /// for breadth-first execution, it would mean dequeuing from the | ||
| /// bottom. | ||
| #[inline] | ||
| pub unsafe fn take_local_job(&self) -> Option<JobRef> { | ||
| if !self.breadth_first { | ||
| self.worker.pop() | ||
| } else { | ||
| self.stealer.steal() | ||
|
||
| } | ||
| } | ||
|
|
||
| /// Wait until the latch is set. Try to keep busy by popping and | ||
|
|
@@ -436,7 +461,7 @@ impl WorkerThread { | |
| // deques, and finally to injected jobs from the | ||
| // outside. The idea is to finish what we started before | ||
| // we take on something new. | ||
| if let Some(job) = self.pop() | ||
| if let Some(job) = self.take_local_job() | ||
| .or_else(|| self.steal()) | ||
| .or_else(|| self.registry.pop_injected_job(self.index)) { | ||
| yields = self.registry.sleep.work_found(self.index, yields); | ||
|
|
@@ -506,9 +531,14 @@ impl WorkerThread { | |
|
|
||
| /// //////////////////////////////////////////////////////////////////////// | ||
|
|
||
| unsafe fn main_loop(worker: Worker<JobRef>, registry: Arc<Registry>, index: usize) { | ||
| unsafe fn main_loop(worker: Worker<JobRef>, | ||
| registry: Arc<Registry>, | ||
| index: usize, | ||
| breadth_first: bool) { | ||
| let worker_thread = WorkerThread { | ||
| worker: worker, | ||
| stealer: registry.thread_infos[index].stealer.clone(), | ||
| breadth_first: breadth_first, | ||
| index: index, | ||
| rng: UnsafeCell::new(rand::weak_rng()), | ||
| registry: registry.clone(), | ||
|
|
@@ -538,7 +568,7 @@ unsafe fn main_loop(worker: Worker<JobRef>, registry: Arc<Registry>, index: usiz | |
| worker_thread.wait_until(®istry.terminate_latch); | ||
|
|
||
| // Should not be any work left in our queue. | ||
| debug_assert!(worker_thread.pop().is_none()); | ||
| debug_assert!(worker_thread.take_local_job().is_none()); | ||
|
|
||
| // let registry know we are done | ||
| registry.thread_infos[index].stopped.set(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this method used anywhere?