Skip to content

Commit

Permalink
Add comments about reentrancy
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Nov 10, 2024
1 parent 16f8dac commit 5af3fc4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/WinRT.Runtime/Interop/IContextCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ static int InvokeCallback(ComCallData* comCallData)

int hresult;

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

0 comments on commit 5af3fc4

Please sign in to comment.