Commit 67124e1c authored by Jörg Höhle's avatar Jörg Höhle Committed by Alexandre Julliard

winmm: Improve initial MIDI player thread synchronisation.

parent 7bd6be07
...@@ -1606,22 +1606,16 @@ static DWORD CALLBACK MMSYSTEM_MidiStream_Player(LPVOID pmt) ...@@ -1606,22 +1606,16 @@ static DWORD CALLBACK MMSYSTEM_MidiStream_Player(LPVOID pmt)
goto the_end; goto the_end;
/* force thread's queue creation */ /* force thread's queue creation */
/* Used to be InitThreadInput16(0, 5); */ PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
/* but following works also with hack in midiStreamOpen */
PeekMessageA(&msg, 0, 0, 0, 0);
/* FIXME: this next line must be called before midiStreamOut or midiStreamRestart are called */
SetEvent(lpMidiStrm->hEvent);
TRACE("Ready to go 1\n");
/* thread is started in paused mode */
SuspendThread(GetCurrentThread());
TRACE("Ready to go 2\n");
lpMidiStrm->dwStartTicks = 0; lpMidiStrm->dwStartTicks = 0;
lpMidiStrm->dwPulses = 0; lpMidiStrm->dwPulses = 0;
lpMidiStrm->lpMidiHdr = 0; lpMidiStrm->lpMidiHdr = 0;
/* midiStreamOpen is waiting for ack */
SetEvent(lpMidiStrm->hEvent);
for (;;) { for (;;) {
lpMidiHdr = lpMidiStrm->lpMidiHdr; lpMidiHdr = lpMidiStrm->lpMidiHdr;
if (!lpMidiHdr) { if (!lpMidiHdr) {
...@@ -1706,8 +1700,7 @@ static DWORD CALLBACK MMSYSTEM_MidiStream_Player(LPVOID pmt) ...@@ -1706,8 +1700,7 @@ static DWORD CALLBACK MMSYSTEM_MidiStream_Player(LPVOID pmt)
} }
the_end: the_end:
TRACE("End of thread\n"); TRACE("End of thread\n");
ExitThread(0); return 0;
return 0; /* for removing the warning, never executed */
} }
/************************************************************************** /**************************************************************************
...@@ -1718,7 +1711,7 @@ static BOOL MMSYSTEM_MidiStream_PostMessage(WINE_MIDIStream* lpMidiStrm, WORD ms ...@@ -1718,7 +1711,7 @@ static BOOL MMSYSTEM_MidiStream_PostMessage(WINE_MIDIStream* lpMidiStrm, WORD ms
if (PostThreadMessageA(lpMidiStrm->dwThreadID, msg, pmt1, pmt2)) { if (PostThreadMessageA(lpMidiStrm->dwThreadID, msg, pmt1, pmt2)) {
MsgWaitForMultipleObjects( 1, &lpMidiStrm->hEvent, FALSE, INFINITE, 0 ); MsgWaitForMultipleObjects( 1, &lpMidiStrm->hEvent, FALSE, INFINITE, 0 );
} else { } else {
WARN("bad PostThreadMessageA\n"); ERR("bad PostThreadMessageA\n");
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
...@@ -1805,6 +1798,8 @@ MMRESULT WINAPI midiStreamOpen(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID, ...@@ -1805,6 +1798,8 @@ MMRESULT WINAPI midiStreamOpen(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID,
/* wait for thread to have started, and for its queue to be created */ /* wait for thread to have started, and for its queue to be created */
WaitForSingleObject(lpMidiStrm->hEvent, INFINITE); WaitForSingleObject(lpMidiStrm->hEvent, INFINITE);
/* start in paused mode */
SuspendThread(lpMidiStrm->hThread);
TRACE("=> (%u/%d) hMidi=%p ret=%d lpMidiStrm=%p\n", TRACE("=> (%u/%d) hMidi=%p ret=%d lpMidiStrm=%p\n",
*lpuDeviceID, lpwm->mld.uDeviceID, *lphMidiStrm, ret, lpMidiStrm); *lpuDeviceID, lpwm->mld.uDeviceID, *lphMidiStrm, ret, lpMidiStrm);
...@@ -1839,7 +1834,7 @@ MMRESULT WINAPI midiStreamOut(HMIDISTRM hMidiStrm, LPMIDIHDR lpMidiHdr, ...@@ -1839,7 +1834,7 @@ MMRESULT WINAPI midiStreamOut(HMIDISTRM hMidiStrm, LPMIDIHDR lpMidiHdr,
if (!PostThreadMessageA(lpMidiStrm->dwThreadID, if (!PostThreadMessageA(lpMidiStrm->dwThreadID,
WINE_MSM_HEADER, cbMidiHdr, WINE_MSM_HEADER, cbMidiHdr,
(LPARAM)lpMidiHdr)) { (LPARAM)lpMidiHdr)) {
WARN("bad PostThreadMessageA\n"); ERR("bad PostThreadMessageA\n");
ret = MMSYSERR_ERROR; ret = MMSYSERR_ERROR;
} }
} }
...@@ -1860,7 +1855,7 @@ MMRESULT WINAPI midiStreamPause(HMIDISTRM hMidiStrm) ...@@ -1860,7 +1855,7 @@ MMRESULT WINAPI midiStreamPause(HMIDISTRM hMidiStrm)
ret = MMSYSERR_INVALHANDLE; ret = MMSYSERR_INVALHANDLE;
} else { } else {
if (SuspendThread(lpMidiStrm->hThread) == 0xFFFFFFFF) { if (SuspendThread(lpMidiStrm->hThread) == 0xFFFFFFFF) {
WARN("bad Suspend (%d)\n", GetLastError()); ERR("bad Suspend (%d)\n", GetLastError());
ret = MMSYSERR_ERROR; ret = MMSYSERR_ERROR;
} }
} }
...@@ -1963,13 +1958,13 @@ MMRESULT WINAPI midiStreamRestart(HMIDISTRM hMidiStrm) ...@@ -1963,13 +1958,13 @@ MMRESULT WINAPI midiStreamRestart(HMIDISTRM hMidiStrm)
DWORD ret; DWORD ret;
/* since we increase the thread suspend count on each midiStreamPause /* since we increase the thread suspend count on each midiStreamPause
* there may be a need for several midiStreamResume * there may be a need for several ResumeThread
*/ */
do { do {
ret = ResumeThread(lpMidiStrm->hThread); ret = ResumeThread(lpMidiStrm->hThread);
} while (ret != 0xFFFFFFFF && ret != 0); } while (ret != 0xFFFFFFFF && ret > 1);
if (ret == 0xFFFFFFFF) { if (ret == 0xFFFFFFFF) {
WARN("bad Resume (%d)\n", GetLastError()); ERR("bad Resume (%d)\n", GetLastError());
ret = MMSYSERR_ERROR; ret = MMSYSERR_ERROR;
} else { } else {
lpMidiStrm->dwStartTicks = GetTickCount() - lpMidiStrm->dwPositionMS; lpMidiStrm->dwStartTicks = GetTickCount() - lpMidiStrm->dwPositionMS;
......
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