@@ -615,6 +615,8 @@ function yield()
615615 end
616616end
617617
618+ @inline set_next_task (t:: Task ) = ccall (:jl_set_next_task , Cvoid, (Any,), t)
619+
618620"""
619621 yield(t::Task, arg = nothing)
620622
@@ -624,7 +626,8 @@ immediately yields to `t` before calling the scheduler.
624626function yield (t:: Task , @nospecialize (x= nothing ))
625627 t. result = x
626628 enq_work (current_task ())
627- return try_yieldto (ensure_rescheduled, Ref (t))
629+ set_next_task (t)
630+ return try_yieldto (ensure_rescheduled)
628631end
629632
630633"""
@@ -637,14 +640,15 @@ or scheduling in any way. Its use is discouraged.
637640"""
638641function yieldto (t:: Task , @nospecialize (x= nothing ))
639642 t. result = x
640- return try_yieldto (identity, Ref (t))
643+ set_next_task (t)
644+ return try_yieldto (identity)
641645end
642646
643- function try_yieldto (undo, reftask :: Ref{Task} )
647+ function try_yieldto (undo)
644648 try
645- ccall (:jl_switchto , Cvoid, (Any,), reftask )
649+ ccall (:jl_switch , Cvoid, () )
646650 catch
647- undo (reftask[] )
651+ undo (ccall ( :jl_get_next_task , Ref{Task}, ()) )
648652 rethrow ()
649653 end
650654 ct = current_task ()
@@ -696,18 +700,19 @@ function trypoptask(W::StickyWorkqueue)
696700 return t
697701end
698702
699- @noinline function poptaskref (W:: StickyWorkqueue )
703+ @noinline function poptask (W:: StickyWorkqueue )
700704 task = trypoptask (W)
701705 if ! (task isa Task)
702706 task = ccall (:jl_task_get_next , Ref{Task}, (Any, Any), trypoptask, W)
703707 end
704- return Ref (task)
708+ set_next_task (task)
709+ nothing
705710end
706711
707712function wait ()
708713 W = Workqueues[Threads. threadid ()]
709- reftask = poptaskref (W)
710- result = try_yieldto (ensure_rescheduled, reftask )
714+ poptask (W)
715+ result = try_yieldto (ensure_rescheduled)
711716 process_events ()
712717 # return when we come out of the queue
713718 return result
0 commit comments