6
6
7
7
use decoder:: MAX_COMPONENTS ;
8
8
use error:: Result ;
9
- use std:: { mem, sync:: mpsc:: { self , Sender } } ;
10
- use std:: thread;
9
+ use std:: { mem, io, sync:: mpsc:: { self , Sender } } ;
11
10
use super :: { RowData , Worker } ;
12
11
use super :: immediate:: ImmediateWorker ;
13
12
@@ -57,10 +56,9 @@ impl Worker for MultiThreadedWorker {
57
56
}
58
57
59
58
fn spawn_worker_thread ( component : usize ) -> Result < Sender < WorkerMsg > > {
60
- let thread_builder = thread:: Builder :: new ( ) . name ( format ! ( "worker thread for component {}" , component) ) ;
61
59
let ( tx, rx) = mpsc:: channel ( ) ;
62
60
63
- thread_builder . spawn ( move || {
61
+ spawn ( component , move || {
64
62
let mut worker = ImmediateWorker :: new_immediate ( ) ;
65
63
66
64
while let Ok ( message) = rx. recv ( ) {
@@ -84,4 +82,24 @@ fn spawn_worker_thread(component: usize) -> Result<Sender<WorkerMsg>> {
84
82
} ) ?;
85
83
86
84
Ok ( tx)
87
- }
85
+ }
86
+
87
+ #[ cfg( feature = "rayon" ) ]
88
+ fn spawn < F > ( _component : usize , func : F ) -> io:: Result < ( ) >
89
+ where
90
+ F : FnOnce ( ) + Send + ' static ,
91
+ {
92
+ rayon:: spawn ( func) ;
93
+ Ok ( ( ) )
94
+ }
95
+
96
+ #[ cfg( not( feature = "rayon" ) ) ]
97
+ fn spawn < F > ( component : usize , func : F ) -> io:: Result < ( ) >
98
+ where
99
+ F : FnOnce ( ) + Send + ' static ,
100
+ {
101
+ let thread_builder =
102
+ std:: thread:: Builder :: new ( ) . name ( format ! ( "worker thread for component {}" , component) ) ;
103
+ thread_builder. spawn ( func) ?;
104
+ Ok ( ( ) )
105
+ }
0 commit comments