Wait until the thread has created its message queue before posting a
authorChristian Costa <titan.costa@wanadoo.fr>
Tue, 11 Jan 2005 15:07:30 +0000 (15:07 +0000)
committerAlexandre Julliard <julliard@winehq.org>
Tue, 11 Jan 2005 15:07:30 +0000 (15:07 +0000)
message otherwise it will be lost.

dlls/dmime/performance.c

index 13fa0364cf0eeb71246d53635fa63c163d8ec09c..dc89129826ccca90859b7fbe44ac3d42827b0905 100644 (file)
@@ -145,10 +145,20 @@ outofthread:
 
 static BOOL PostMessageToProcessMsgThread(IDirectMusicPerformance8Impl* This, UINT iMsg) {
   if (FALSE == This->procThreadTicStarted && PROCESSMSG_EXIT != iMsg) {
+    BOOL res;
     This->procThread = CreateThread(NULL, 0, ProcessMsgThread, This, 0, &This->procThreadId);
     if (NULL == This->procThread) return FALSE;
     SetThreadPriority(This->procThread, THREAD_PRIORITY_TIME_CRITICAL);
     This->procThreadTicStarted = TRUE;
+    while(1) {
+      res = PostThreadMessageA(This->procThreadId, iMsg, 0, 0);
+      /* Let the thread creates its message queue (with MsgWaitForMultipleObjects call) by yielding and retrying */
+      if (!res && (GetLastError() == ERROR_INVALID_THREAD_ID))
+       Sleep(0);
+      else
+       break;
+    }
+    return res;
   }
   return PostThreadMessageA(This->procThreadId, iMsg, 0, 0);
 }