Commit 4df1a583 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

quartz: Use a condition variable to wake up the system clock advise thread.

parent 6c0ddfee
......@@ -42,10 +42,11 @@ struct system_clock
IUnknown *outer_unk;
LONG refcount;
BOOL thread_created;
HANDLE thread, notify_event, stop_event;
BOOL thread_created, thread_stopped;
HANDLE thread;
REFERENCE_TIME last_time;
CRITICAL_SECTION cs;
CONDITION_VARIABLE cv;
struct list sinks;
};
......@@ -96,11 +97,12 @@ static ULONG WINAPI system_clock_inner_Release(IUnknown *iface)
{
if (clock->thread)
{
SetEvent(clock->stop_event);
EnterCriticalSection(&clock->cs);
clock->thread_stopped = TRUE;
LeaveCriticalSection(&clock->cs);
WakeConditionVariable(&clock->cv);
WaitForSingleObject(clock->thread, INFINITE);
CloseHandle(clock->thread);
CloseHandle(clock->notify_event);
CloseHandle(clock->stop_event);
}
clock->cs.DebugInfo->Spare[0] = 0;
DeleteCriticalSection(&clock->cs);
......@@ -128,7 +130,6 @@ static DWORD WINAPI SystemClockAdviseThread(void *param)
struct system_clock *clock = param;
struct advise_sink *sink, *cursor;
REFERENCE_TIME current_time;
HANDLE handles[2] = {clock->stop_event, clock->notify_event};
TRACE("Starting advise thread for clock %p.\n", clock);
......@@ -162,11 +163,14 @@ static DWORD WINAPI SystemClockAdviseThread(void *param)
timeout = min(timeout, (sink->due_time - current_time) / 10000);
}
SleepConditionVariableCS(&clock->cv, &clock->cs, timeout);
if (clock->thread_stopped)
{
LeaveCriticalSection(&clock->cs);
if (WaitForMultipleObjects(2, handles, FALSE, timeout) == 0)
return 0;
}
LeaveCriticalSection(&clock->cs);
}
}
static HRESULT add_sink(struct system_clock *clock, DWORD_PTR handle,
......@@ -194,11 +198,9 @@ static HRESULT add_sink(struct system_clock *clock, DWORD_PTR handle,
if (!InterlockedCompareExchange(&clock->thread_created, TRUE, FALSE))
{
clock->notify_event = CreateEventW(NULL, FALSE, FALSE, NULL);
clock->stop_event = CreateEventW(NULL, TRUE, FALSE, NULL);
clock->thread = CreateThread(NULL, 0, SystemClockAdviseThread, clock, 0, NULL);
}
SetEvent(clock->notify_event);
WakeConditionVariable(&clock->cv);
*cookie = sink->cookie;
return S_OK;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment