@@ -1145,16 +1145,6 @@ function throwto(t::Task, @nospecialize exc)
11451145    return  try_yieldto (identity)
11461146end 
11471147
1148- @inline  function  wait_forever ()
1149-     while  true 
1150-         wait ()
1151-     end 
1152- end 
1153- 
1154- const  get_sched_task =  OncePerThread {Task} () do 
1155-     Task (wait_forever)
1156- end 
1157- 
11581148function  ensure_rescheduled (othertask:: Task )
11591149    ct =  current_task ()
11601150    W =  workqueue_for (Threads. threadid ())
@@ -1191,39 +1181,25 @@ end
11911181
11921182checktaskempty =  Partr. multiq_check_empty
11931183
1184+ @noinline  function  poptask (W:: StickyWorkqueue )
1185+     task =  trypoptask (W)
1186+     if  ! (task isa  Task)
1187+         task =  ccall (:jl_task_get_next , Ref{Task}, (Any, Any, Any), trypoptask, W, checktaskempty)
1188+     end 
1189+     set_next_task (task)
1190+     nothing 
1191+ end 
1192+ 
11941193function  wait ()
11951194    ct =  current_task ()
11961195    #  [task] user_time -yield-or-done-> wait_time
11971196    record_running_time! (ct)
1198-     #  let GC run
11991197    GC. safepoint ()
1200-     #  check for libuv events
1201-     process_events ()
1202- 
1203-     #  get the next task to run
1204-     result =  nothing 
1205-     have_result =  false 
12061198    W =  workqueue_for (Threads. threadid ())
1207-     task =  trypoptask (W)
1208-     if  ! (task isa  Task)
1209-         #  No tasks to run; switch to the scheduler task to run the
1210-         #  thread sleep logic.
1211-         sched_task =  get_sched_task ()
1212-         if  ct != =  sched_task
1213-             result =  yieldto (sched_task)
1214-             have_result =  true 
1215-         else 
1216-             task =  ccall (:jl_task_get_next , Ref{Task}, (Any, Any, Any),
1217-                          trypoptask, W, checktaskempty)
1218-         end 
1219-     end 
1220-     #  We may have already switched tasks (via the scheduler task), so
1221-     #  only switch if we haven't.
1222-     if  ! have_result
1223-         @assert  task isa  Task
1224-         set_next_task (task)
1225-         result =  try_yieldto (ensure_rescheduled)
1226-     end 
1199+     poptask (W)
1200+     result =  try_yieldto (ensure_rescheduled)
1201+     process_events ()
1202+     #  return when we come out of the queue
12271203    return  result
12281204end 
12291205
0 commit comments