@@ -40,25 +40,16 @@ public void YieldToInvokerThread()
40
40
{
41
41
// Wake invoker thread.
42
42
invokerThreadTurn . Set ( ) ;
43
-
44
- // Block user-code thread.
45
- userCodeThreadTurn . Reset ( ) ;
46
43
userCodeThreadTurn . WaitOne ( ) ;
47
44
}
48
45
49
46
/// <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.
52
48
/// </summary>
53
49
/// <param name="completionHandle">The WaitHandle tracking if the user-code thread completed.</param>
54
50
/// <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 )
56
52
{
57
- // Wake user-code thread
58
- userCodeThreadTurn . Set ( ) ;
59
-
60
- // Get invoker thread ready to block
61
- invokerThreadTurn . Reset ( ) ;
62
53
63
54
// Wake up when either the user-code returns, or when we're yielded-to for `await`'ing.
64
55
var index = WaitHandle . WaitAny ( new [ ] { completionHandle , invokerThreadTurn } ) ;
@@ -67,13 +58,12 @@ public bool YieldToUserCodeThread(WaitHandle completionHandle)
67
58
}
68
59
69
60
/// <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.
73
63
/// </summary>
74
- public void GuaranteeUserCodeTurn ( )
64
+ public void WakeUserCodeThread ( )
75
65
{
76
- userCodeThreadTurn . WaitOne ( ) ;
66
+ userCodeThreadTurn . Set ( ) ;
77
67
}
78
68
}
79
69
}
0 commit comments