1
1
use crossbeam:: sync:: SegQueue ;
2
- use crossbeam_deque:: { Deque , Steal , Stealer } ;
2
+ use crossbeam_deque:: { self as deque , Pop , Steal , Stealer , Worker } ;
3
3
#[ cfg( rayon_unstable) ]
4
4
use internal:: task:: Task ;
5
5
#[ cfg( rayon_unstable) ]
@@ -102,8 +102,15 @@ impl Registry {
102
102
let n_threads = builder. get_num_threads ( ) ;
103
103
let breadth_first = builder. get_breadth_first ( ) ;
104
104
105
- let workers: Vec < _ > = ( 0 ..n_threads) . map ( |_| Deque :: new ( ) ) . collect ( ) ;
106
- let stealers: Vec < _ > = workers. iter ( ) . map ( |d| d. stealer ( ) ) . collect ( ) ;
105
+ let ( workers, stealers) : ( Vec < _ > , Vec < _ > ) = ( 0 ..n_threads)
106
+ . map ( |_| {
107
+ if breadth_first {
108
+ deque:: fifo ( )
109
+ } else {
110
+ deque:: lifo ( )
111
+ }
112
+ } )
113
+ . unzip ( ) ;
107
114
108
115
let registry = Arc :: new ( Registry {
109
116
thread_infos : stealers. into_iter ( ) . map ( |s| ThreadInfo :: new ( s) ) . collect ( ) ,
@@ -127,9 +134,7 @@ impl Registry {
127
134
if let Some ( stack_size) = builder. get_stack_size ( ) {
128
135
b = b. stack_size ( stack_size) ;
129
136
}
130
- if let Err ( e) =
131
- b. spawn ( move || unsafe { main_loop ( worker, registry, index, breadth_first) } )
132
- {
137
+ if let Err ( e) = b. spawn ( move || unsafe { main_loop ( worker, registry, index) } ) {
133
138
return Err ( ThreadPoolBuildError :: new ( ErrorKind :: IOError ( e) ) ) ;
134
139
}
135
140
}
@@ -467,16 +472,13 @@ impl ThreadInfo {
467
472
468
473
pub struct WorkerThread {
469
474
/// the "worker" half of our local deque
470
- worker : Deque < JobRef > ,
475
+ worker : Worker < JobRef > ,
471
476
472
477
/// local queue used for `spawn_fifo` indirection
473
478
fifo : JobFifo ,
474
479
475
480
index : usize ,
476
481
477
- /// are these workers configured to steal breadth-first or not?
478
- breadth_first : bool ,
479
-
480
482
/// A weak random number generator.
481
483
rng : XorShift64Star ,
482
484
@@ -535,7 +537,7 @@ impl WorkerThread {
535
537
536
538
#[ inline]
537
539
pub fn local_deque_is_empty ( & self ) -> bool {
538
- self . worker . len ( ) == 0
540
+ self . worker . is_empty ( )
539
541
}
540
542
541
543
/// Attempts to obtain a "local" job -- typically this means
@@ -544,15 +546,11 @@ impl WorkerThread {
544
546
/// bottom.
545
547
#[ inline]
546
548
pub unsafe fn take_local_job ( & self ) -> Option < JobRef > {
547
- if !self . breadth_first {
548
- self . worker . pop ( )
549
- } else {
550
- loop {
551
- match self . worker . steal ( ) {
552
- Steal :: Empty => return None ,
553
- Steal :: Data ( d) => return Some ( d) ,
554
- Steal :: Retry => { }
555
- }
549
+ loop {
550
+ match self . worker . pop ( ) {
551
+ Pop :: Empty => return None ,
552
+ Pop :: Data ( d) => return Some ( d) ,
553
+ Pop :: Retry => { }
556
554
}
557
555
}
558
556
}
@@ -620,7 +618,7 @@ impl WorkerThread {
620
618
/// local work to do.
621
619
unsafe fn steal ( & self ) -> Option < JobRef > {
622
620
// we only steal when we don't have any work to do locally
623
- debug_assert ! ( self . worker . pop ( ) . is_none ( ) ) ;
621
+ debug_assert ! ( self . local_deque_is_empty ( ) ) ;
624
622
625
623
// otherwise, try to steal
626
624
let num_threads = self . registry . thread_infos . len ( ) ;
@@ -654,16 +652,10 @@ impl WorkerThread {
654
652
655
653
/// ////////////////////////////////////////////////////////////////////////
656
654
657
- unsafe fn main_loop (
658
- worker : Deque < JobRef > ,
659
- registry : Arc < Registry > ,
660
- index : usize ,
661
- breadth_first : bool ,
662
- ) {
655
+ unsafe fn main_loop ( worker : Worker < JobRef > , registry : Arc < Registry > , index : usize ) {
663
656
let worker_thread = WorkerThread {
664
657
worker : worker,
665
658
fifo : JobFifo :: new ( ) ,
666
- breadth_first : breadth_first,
667
659
index : index,
668
660
rng : XorShift64Star :: new ( ) ,
669
661
registry : registry. clone ( ) ,
0 commit comments