@@ -112,13 +112,6 @@ struct Core {
112112 /// Used to schedule bookkeeping tasks every so often.
113113 tick : u32 ,
114114
115- /// When a task is scheduled from a worker, it is stored in this slot. The
116- /// worker will check this slot for a task **before** checking the run
117- /// queue. This effectively results in the **last** scheduled task to be run
118- /// next (LIFO). This is an optimization for improving locality which
119- /// benefits message passing patterns and helps to reduce latency.
120- lifo_slot : Option < Notified > ,
121-
122115 /// When `true`, locally scheduled tasks go to the LIFO slot. When `false`,
123116 /// they go to the back of the `run_queue`.
124117 lifo_enabled : bool ,
@@ -280,7 +273,6 @@ pub(super) fn create(
280273
281274 cores. push ( Box :: new ( Core {
282275 tick : 0 ,
283- lifo_slot : None ,
284276 lifo_enabled : !config. disable_lifo_slot ,
285277 run_queue,
286278 #[ cfg( all( tokio_unstable, feature = "time" ) ) ]
@@ -440,7 +432,7 @@ where
440432 // If we heavily call `spawn_blocking`, there might be no available thread to
441433 // run this core. Except for the task in the lifo_slot, all tasks can be
442434 // stolen, so we move the task out of the lifo_slot to the run_queue.
443- if let Some ( task) = core. lifo_slot . take ( ) {
435+ if let Some ( task) = core. run_queue . pop_lifo ( ) {
444436 core. run_queue
445437 . push_back_or_overflow ( task, & * cx. worker . handle , & mut core. stats ) ;
446438 }
@@ -670,7 +662,7 @@ impl Context {
670662 } ;
671663
672664 // Check for a task in the LIFO slot
673- let task = match core. lifo_slot . take ( ) {
665+ let task = match core. run_queue . pop_lifo ( ) {
674666 Some ( task) => task,
675667 None => {
676668 self . reset_lifo_enabled ( & mut core) ;
@@ -1079,7 +1071,7 @@ impl Core {
10791071 }
10801072
10811073 fn next_local_task ( & mut self ) -> Option < Notified > {
1082- self . lifo_slot . take ( ) . or_else ( || self . run_queue . pop ( ) )
1074+ self . run_queue . pop_lifo ( ) . or_else ( || self . run_queue . pop ( ) )
10831075 }
10841076
10851077 /// Function responsible for stealing tasks from another worker
@@ -1135,7 +1127,7 @@ impl Core {
11351127 }
11361128
11371129 fn has_tasks ( & self ) -> bool {
1138- self . lifo_slot . is_some ( ) || self . run_queue . has_tasks ( )
1130+ self . run_queue . has_tasks ( )
11391131 }
11401132
11411133 fn should_notify_others ( & self ) -> bool {
@@ -1144,7 +1136,7 @@ impl Core {
11441136 if self . is_searching {
11451137 return false ;
11461138 }
1147- self . lifo_slot . is_some ( ) as usize + self . run_queue . len ( ) > 1
1139+ self . run_queue . len ( ) > 1
11481140 }
11491141
11501142 /// Prepares the worker state for parking.
@@ -1306,29 +1298,23 @@ impl Handle {
13061298 // task must always be pushed to the back of the queue, enabling other
13071299 // tasks to be executed. If **not** a yield, then there is more
13081300 // flexibility and the task may go to the front of the queue.
1309- let should_notify = if is_yield || !core. lifo_enabled {
1301+ if is_yield || !core. lifo_enabled {
13101302 core. run_queue
13111303 . push_back_or_overflow ( task, self , & mut core. stats ) ;
1312- true
13131304 } else {
13141305 // Push to the LIFO slot
1315- let prev = core. lifo_slot . take ( ) ;
1316- let ret = prev. is_some ( ) ;
1317-
1318- if let Some ( prev) = prev {
1306+ if let Some ( prev) = core. run_queue . push_lifo ( task) {
1307+ // There was a previous task in the LIFO slot which needs
1308+ // to be pushed to the back of the run queue.
13191309 core. run_queue
13201310 . push_back_or_overflow ( prev, self , & mut core. stats ) ;
13211311 }
1322-
1323- core. lifo_slot = Some ( task) ;
1324-
1325- ret
13261312 } ;
13271313
13281314 // Only notify if not currently parked. If `park` is `None`, then the
13291315 // scheduling is from a resource driver. As notifications often come in
13301316 // batches, the notification is delayed until the park is complete.
1331- if should_notify && core. park . is_some ( ) {
1317+ if core. park . is_some ( ) {
13321318 self . notify_parked_local ( ) ;
13331319 }
13341320 }
0 commit comments