diff --git a/dll/win32/kernel32/client/timerqueue.c b/dll/win32/kernel32/client/timerqueue.c index 5a24a258b9f..83656880ba4 100644 --- a/dll/win32/kernel32/client/timerqueue.c +++ b/dll/win32/kernel32/client/timerqueue.c @@ -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; }