From 419e92812b4d97c94b341497081c6fa07ecb4e04 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Sat, 23 Apr 2005 19:03:47 +0000 Subject: [PATCH] Set thread priority for timer thread. Add timer thread priority test. --- dlls/winmm/tests/timer.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ dlls/winmm/time.c | 1 + 2 files changed, 57 insertions(+) diff --git a/dlls/winmm/tests/timer.c b/dlls/winmm/tests/timer.c index 170b0e0047f..dc249f69ee5 100644 --- a/dlls/winmm/tests/timer.c +++ b/dlls/winmm/tests/timer.c @@ -142,6 +142,60 @@ static void test_timer(UINT period, UINT resolution) dwMin, dwMax, sum / (count - 1), sqrt(deviation / (count - 2))); } +const char * get_priority(int priority) +{ + static char tmp[32]; +#define STR(x) case x: return #x + switch(priority) { + STR(THREAD_PRIORITY_LOWEST); + STR(THREAD_PRIORITY_BELOW_NORMAL); + STR(THREAD_PRIORITY_NORMAL); + STR(THREAD_PRIORITY_HIGHEST); + STR(THREAD_PRIORITY_ABOVE_NORMAL); + STR(THREAD_PRIORITY_TIME_CRITICAL); + STR(THREAD_PRIORITY_IDLE); + } + sprintf(tmp, "UNKNOWN(%d)", priority); + return tmp; +} + +static int priority = 0; +static BOOL disable_boost = FALSE; +static BOOL fired = FALSE; + +void CALLBACK priorityTimeProc(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2) +{ + BOOL res; + priority = GetThreadPriority(GetCurrentThread()); + res = GetThreadPriorityBoost(GetCurrentThread(), &disable_boost); + ok(res == 0, "GetThreadPriorityBoost() failed, GetLastError() = %08lx\n", GetLastError()); + fired = TRUE; +} + +void test_priority() +{ + UINT id; + + fired = FALSE; + + id = timeSetEvent(100, 100, priorityTimeProc, 0, TIME_ONESHOT); + ok(id != 0, "timeSetEvent(100, 100, %p, 0, TIME_ONESHOT) returned %d, " + "should have returned id > 0\n", priorityTimeProc, id); + if (id == 0) + return; + + Sleep(200); + + ok(fired == TRUE, "Callback not called\n"); + if (fired) + { + ok(priority == THREAD_PRIORITY_TIME_CRITICAL, + "thread priority is %s, should be THREAD_PRIORITY_TIME_CRITICAL\n", + get_priority(priority)); + ok(disable_boost == FALSE, "disable thread boost should be FALSE\n"); + } +} + START_TEST(timer) { test_timeGetDevCaps(); @@ -163,4 +217,6 @@ START_TEST(timer) test_timer(20, 10); test_timer(20, 20); } + + test_priority(); } diff --git a/dlls/winmm/time.c b/dlls/winmm/time.c index 3b99845aa72..a590f6a687f 100644 --- a/dlls/winmm/time.c +++ b/dlls/winmm/time.c @@ -265,6 +265,7 @@ void TIME_MMTimeStart(void) TIME_hWakeEvent = CreateEventW(NULL, FALSE, FALSE, NULL); TIME_TimeToDie = FALSE; TIME_hMMTimer = CreateThread(NULL, 0, TIME_MMSysTimeThread, WINMM_IData, 0, NULL); + SetThreadPriority(TIME_hMMTimer, THREAD_PRIORITY_TIME_CRITICAL); } } -- 2.11.4.GIT