@@ -5,7 +5,7 @@ use std::thread;
55use std:: time:: Duration ;
66
77use crossbeam_channel:: { bounded, Receiver , Sender } ;
8- use lazy_static :: lazy_static ;
8+ use once_cell :: sync :: Lazy ;
99
1010use crate :: task:: task:: { JoinHandle , Tag } ;
1111use crate :: utils:: abort_on_panic;
@@ -19,30 +19,30 @@ struct Pool {
1919 receiver : Receiver < async_task:: Task < Tag > > ,
2020}
2121
22- lazy_static ! {
23- static ref POOL : Pool = {
24- for _ in 0 .. 2 {
25- thread :: Builder :: new ( )
26- . name ( "async-blocking-driver" . to_string ( ) )
27- . spawn ( || abort_on_panic( || {
22+ static POOL : Lazy < Pool > = Lazy :: new ( || {
23+ for _ in 0 .. 2 {
24+ thread :: Builder :: new ( )
25+ . name ( "async-blocking-driver" . to_string ( ) )
26+ . spawn ( || {
27+ abort_on_panic ( || {
2828 for task in & POOL . receiver {
2929 task. run ( ) ;
3030 }
31- } ) )
32- . expect ( "cannot start a thread driving blocking tasks" ) ;
33- }
34-
35- // We want to use an unbuffered channel here to help
36- // us drive our dynamic control. In effect, the
37- // kernel's scheduler becomes the queue, reducing
38- // the number of buffers that work must flow through
39- // before being acted on by a core. This helps keep
40- // latency snappy in the overall async system by
41- // reducing bufferbloat.
42- let ( sender , receiver ) = bounded ( 0 ) ;
43- Pool { sender, receiver }
44- } ;
45- }
31+ } )
32+ } )
33+ . expect ( "cannot start a thread driving blocking tasks" ) ;
34+ }
35+
36+ // We want to use an unbuffered channel here to help
37+ // us drive our dynamic control. In effect, the
38+ // kernel's scheduler becomes the queue, reducing
39+ // the number of buffers that work must flow through
40+ // before being acted on by a core. This helps keep
41+ // latency snappy in the overall async system by
42+ // reducing bufferbloat.
43+ let ( sender, receiver) = bounded ( 0 ) ;
44+ Pool { sender , receiver }
45+ } ) ;
4646
4747// Create up to MAX_THREADS dynamic blocking task worker threads.
4848// Dynamic threads will terminate themselves if they don't
0 commit comments