d3d9/tests: Avoid a shift overflow in render_state_test_data_init.
[wine] / dlls / winmm / time.c
index 3d45fd9..e055f6b 100644 (file)
@@ -243,16 +243,19 @@ static DWORD CALLBACK TIME_MMSysTimeThread(LPVOID arg)
 static void TIME_MMTimeStart(void)
 {
     TIME_TimeToDie = 0;
-    if (!TIME_hMMTimer) {
-        HMODULE mod;
-        if (pipe(TIME_fdWake) < 0)
-        {
+
+    if (TIME_fdWake[0] < 0) {
+        if (pipe(TIME_fdWake) < 0) {
             TIME_fdWake[0] = TIME_fdWake[1] = -1;
             ERR("Cannot create pipe: %s\n", strerror(errno));
         } else {
             fcntl(TIME_fdWake[0], F_SETFL, O_NONBLOCK);
             fcntl(TIME_fdWake[1], F_SETFL, O_NONBLOCK);
         }
+    }
+
+    if (!TIME_hMMTimer) {
+        HMODULE mod;
         GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)TIME_MMSysTimeThread, &mod);
         TIME_hMMTimer = CreateThread(NULL, 0, TIME_MMSysTimeThread, mod, 0, NULL);
         SetThreadPriority(TIME_hMMTimer, THREAD_PRIORITY_TIME_CRITICAL);
@@ -369,8 +372,11 @@ MMRESULT WINAPI timeKillEvent(UINT wID)
            break;
        }
     }
-    if (list_empty(&timer_list))
+    if (list_empty(&timer_list)) {
+        char c = 'q';
         TIME_TimeToDie = 1;
+        write(TIME_fdWake[1], &c, sizeof(c));
+    }
     LeaveCriticalSection(&WINMM_cs);
 
     if (!lpSelf)