[KERNEL32] Make creation of a default timer queue thread safe

This commit is contained in:
Alex Mendoza
2026-07-28 12:37:25 +02:00
committed by George Bișoc
parent 3f14a78b4f
commit 73e69a62d3

View File

@@ -19,15 +19,19 @@ HANDLE BasepDefaultTimerQueue = NULL;
/* PRIVATE FUNCTIONS **********************************************************/
/* FIXME - make this thread safe */
BOOL
WINAPI
BasepCreateDefaultTimerQueue(VOID)
{
NTSTATUS Status;
HANDLE TimerQueue;
/* Already initialized */
if (BasepDefaultTimerQueue != NULL)
return TRUE;
/* Create the timer queue */
Status = RtlCreateTimerQueue(&BasepDefaultTimerQueue);
Status = RtlCreateTimerQueue(&TimerQueue);
if (!NT_SUCCESS(Status))
{
BaseSetLastNTError(Status);
@@ -35,6 +39,14 @@ BasepCreateDefaultTimerQueue(VOID)
return FALSE;
}
/* Try to publish it. If another thread already did, throw ours away */
if (InterlockedCompareExchangePointer((PVOID *)&BasepDefaultTimerQueue,
TimerQueue,
NULL) != NULL)
{
RtlDeleteTimerQueueEx(TimerQueue, NULL);
}
return TRUE;
}