Windows: fix KDF completion lifetime

Hold a requester reference until header parsing can no longer enqueue KDFs.
This prevents stale completion signals from allowing cleanup while workers
still use request-owned state.

Add bounded tests of the production pool and caller completion protocol.
This commit is contained in:
Mounir IDRASSI
2026-10-16 18:06:08 +09:00
parent 0cb9fad329
commit 9ff43ba473
5 changed files with 415 additions and 9 deletions
+1 -1
View File
@@ -291,6 +291,7 @@ static TC_THREAD_PROC EncryptionThreadProc (void *threadArg)
InterlockedExchange (workItem->KeyDerivation.CompletionFlag, TRUE);
TC_SET_EVENT (*workItem->KeyDerivation.CompletionEvent);
// The requester retains a reference until it has finished submitting work.
if (InterlockedDecrement (workItem->KeyDerivation.OutstandingWorkItemCount) == 0)
TC_SET_EVENT (*workItem->KeyDerivation.NoOutstandingWorkItemEvent);
@@ -581,7 +582,6 @@ void EncryptionThreadPoolBeginKeyDerivation (TC_EVENT *completionEvent, TC_EVENT
workItem->KeyDerivation.pAbortKeyDerivation = pAbortKeyDerivation;
InterlockedIncrement (outstandingWorkItemCount);
TC_CLEAR_EVENT (*noOutstandingWorkItemEvent);
SetWorkItemState (workItem, WorkItemReady);
TC_SET_EVENT (WorkItemReadyEvent);