@@ -615,6 +615,8 @@ function yield()
615
615
end
616
616
end
617
617
618
+ @inline set_next_task (t:: Task ) = ccall (:jl_set_next_task , Cvoid, (Any,), t)
619
+
618
620
"""
619
621
yield(t::Task, arg = nothing)
620
622
@@ -624,7 +626,8 @@ immediately yields to `t` before calling the scheduler.
624
626
function yield (t:: Task , @nospecialize (x= nothing ))
625
627
t. result = x
626
628
enq_work (current_task ())
627
- return try_yieldto (ensure_rescheduled, Ref (t))
629
+ set_next_task (t)
630
+ return try_yieldto (ensure_rescheduled)
628
631
end
629
632
630
633
"""
@@ -637,14 +640,15 @@ or scheduling in any way. Its use is discouraged.
637
640
"""
638
641
function yieldto (t:: Task , @nospecialize (x= nothing ))
639
642
t. result = x
640
- return try_yieldto (identity, Ref (t))
643
+ set_next_task (t)
644
+ return try_yieldto (identity)
641
645
end
642
646
643
- function try_yieldto (undo, reftask :: Ref{Task} )
647
+ function try_yieldto (undo)
644
648
try
645
- ccall (:jl_switchto , Cvoid, (Any,), reftask )
649
+ ccall (:jl_switch , Cvoid, () )
646
650
catch
647
- undo (reftask[] )
651
+ undo (ccall ( :jl_get_next_task , Ref{Task}, ()) )
648
652
rethrow ()
649
653
end
650
654
ct = current_task ()
@@ -696,18 +700,19 @@ function trypoptask(W::StickyWorkqueue)
696
700
return t
697
701
end
698
702
699
- @noinline function poptaskref (W:: StickyWorkqueue )
703
+ @noinline function poptask (W:: StickyWorkqueue )
700
704
task = trypoptask (W)
701
705
if ! (task isa Task)
702
706
task = ccall (:jl_task_get_next , Ref{Task}, (Any, Any), trypoptask, W)
703
707
end
704
- return Ref (task)
708
+ set_next_task (task)
709
+ nothing
705
710
end
706
711
707
712
function wait ()
708
713
W = Workqueues[Threads. threadid ()]
709
- reftask = poptaskref (W)
710
- result = try_yieldto (ensure_rescheduled, reftask )
714
+ poptask (W)
715
+ result = try_yieldto (ensure_rescheduled)
711
716
process_events ()
712
717
# return when we come out of the queue
713
718
return result
0 commit comments