Skip to content

Commit 5af3fc4

Browse files
committed
Add comments about reentrancy
1 parent 16f8dac commit 5af3fc4

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/WinRT.Runtime/Interop/IContextCallback.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ static int InvokeCallback(ComCallData* comCallData)
7070

7171
int hresult;
7272

73+
// We use a thread local static field to efficiently store the state that's used by the callback. Note that this
74+
// is safe with respect to reentrancy, as the target callback will never try to switch back on the original thread.
75+
// We're only ever switching once on the original context, only to release the object reference that is passed as
76+
// state. There is no way for that to possibly switch back on the starting thread. As such, using a thread static
77+
// field to pass the state to the target context (we need to store it somewhere on the managed heap) is fine.
7378
fixed (object* statePtr = &CallbackData.PerThreadObject)
7479
{
7580
CallbackData callbackData;

0 commit comments

Comments
 (0)