@@ -40,25 +40,16 @@ public void YieldToInvokerThread()
4040 {
4141 // Wake invoker thread.
4242 invokerThreadTurn . Set ( ) ;
43-
44- // Block user-code thread.
45- userCodeThreadTurn . Reset ( ) ;
4643 userCodeThreadTurn . WaitOne ( ) ;
4744 }
4845
4946 /// <summary>
50- /// Blocks Orchestration-invoker thread, wakes up user-code thread.
51- /// This is usually used after the invoker has a result for the PS orchestrator.
47+ /// Blocks Orchestration-invoker thread until the user-code thread completes or yields.
5248 /// </summary>
5349 /// <param name="completionHandle">The WaitHandle tracking if the user-code thread completed.</param>
5450 /// <returns>True if the user-code thread completed, False if it requests an API to be awaited.</returns>
55- public bool YieldToUserCodeThread ( WaitHandle completionHandle )
51+ public bool WaitForInvokerThreadTurn ( WaitHandle completionHandle )
5652 {
57- // Wake user-code thread
58- userCodeThreadTurn . Set ( ) ;
59-
60- // Get invoker thread ready to block
61- invokerThreadTurn . Reset ( ) ;
6253
6354 // Wake up when either the user-code returns, or when we're yielded-to for `await`'ing.
6455 var index = WaitHandle . WaitAny ( new [ ] { completionHandle , invokerThreadTurn } ) ;
@@ -67,13 +58,12 @@ public bool YieldToUserCodeThread(WaitHandle completionHandle)
6758 }
6859
6960 /// <summary>
70- /// Blocks user code thread if the orchestrator-invoker thread is currently running.
71- /// This guarantees that the user-code thread and the orchestration-invoker thread run one
72- /// at a time after this point.
61+ /// Wakes up the user-code thread without blocking the invoker thread.
62+ /// The invoker thread should block itself afterwards to prevent races.
7363 /// </summary>
74- public void GuaranteeUserCodeTurn ( )
64+ public void WakeUserCodeThread ( )
7565 {
76- userCodeThreadTurn . WaitOne ( ) ;
66+ userCodeThreadTurn . Set ( ) ;
7767 }
7868 }
7969}
0 commit comments