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

winmm: PlaySound concurrency cleanup.

parent a0dbd846
...@@ -44,7 +44,6 @@ typedef struct tagWINE_PLAYSOUND ...@@ -44,7 +44,6 @@ typedef struct tagWINE_PLAYSOUND
LPCWSTR pszSound; LPCWSTR pszSound;
HMODULE hMod; HMODULE hMod;
DWORD fdwSound; DWORD fdwSound;
HANDLE hThread;
struct tagWINE_PLAYSOUND* lpNext; struct tagWINE_PLAYSOUND* lpNext;
} WINE_PLAYSOUND; } WINE_PLAYSOUND;
...@@ -215,7 +214,6 @@ static void PlaySound_Free(WINE_PLAYSOUND* wps) ...@@ -215,7 +214,6 @@ static void PlaySound_Free(WINE_PLAYSOUND* wps)
if (PlaySoundList == NULL) SetEvent(psLastEvent); if (PlaySoundList == NULL) SetEvent(psLastEvent);
LeaveCriticalSection(&WINMM_cs); LeaveCriticalSection(&WINMM_cs);
if (wps->bAlloc) HeapFree(GetProcessHeap(), 0, (void*)wps->pszSound); if (wps->bAlloc) HeapFree(GetProcessHeap(), 0, (void*)wps->pszSound);
if (wps->hThread) CloseHandle(wps->hThread);
HeapFree(GetProcessHeap(), 0, wps); HeapFree(GetProcessHeap(), 0, wps);
} }
...@@ -258,7 +256,8 @@ static WINE_PLAYSOUND* PlaySound_Alloc(const void* pszSound, HMODULE hmod, ...@@ -258,7 +256,8 @@ static WINE_PLAYSOUND* PlaySound_Alloc(const void* pszSound, HMODULE hmod,
return wps; return wps;
oom_error: oom_error:
PlaySound_Free(wps); if (wps->bAlloc) HeapFree(GetProcessHeap(), 0, (void*)wps->pszSound);
HeapFree(GetProcessHeap(), 0, wps);
return NULL; return NULL;
} }
...@@ -377,6 +376,8 @@ static DWORD WINAPI proc_PlaySound(LPVOID arg) ...@@ -377,6 +376,8 @@ static DWORD WINAPI proc_PlaySound(LPVOID arg)
(LPSTR)&mmckInfo.ckid, mmckInfo.fccType, mmckInfo.cksize); (LPSTR)&mmckInfo.ckid, mmckInfo.fccType, mmckInfo.cksize);
lpWaveFormat = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize); lpWaveFormat = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
if (!lpWaveFormat)
goto errCleanUp;
if (mmioRead(hmmio, (HPSTR)lpWaveFormat, mmckInfo.cksize) < sizeof(PCMWAVEFORMAT)) if (mmioRead(hmmio, (HPSTR)lpWaveFormat, mmckInfo.cksize) < sizeof(PCMWAVEFORMAT))
goto errCleanUp; goto errCleanUp;
...@@ -398,6 +399,8 @@ static DWORD WINAPI proc_PlaySound(LPVOID arg) ...@@ -398,6 +399,8 @@ static DWORD WINAPI proc_PlaySound(LPVOID arg)
(LPSTR)&mmckInfo.ckid, mmckInfo.fccType, mmckInfo.cksize); (LPSTR)&mmckInfo.ckid, mmckInfo.fccType, mmckInfo.cksize);
s.hEvent = CreateEventW(NULL, FALSE, FALSE, NULL); s.hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
if (!s.hEvent)
goto errCleanUp;
if (waveOutOpen(&hWave, WAVE_MAPPER, lpWaveFormat, (DWORD_PTR)PlaySound_Callback, if (waveOutOpen(&hWave, WAVE_MAPPER, lpWaveFormat, (DWORD_PTR)PlaySound_Callback,
(DWORD_PTR)&s, CALLBACK_FUNCTION) != MMSYSERR_NOERROR) (DWORD_PTR)&s, CALLBACK_FUNCTION) != MMSYSERR_NOERROR)
...@@ -407,6 +410,8 @@ static DWORD WINAPI proc_PlaySound(LPVOID arg) ...@@ -407,6 +410,8 @@ static DWORD WINAPI proc_PlaySound(LPVOID arg)
bufsize = (((lpWaveFormat->nAvgBytesPerSec / 3) - 1) / lpWaveFormat->nBlockAlign + 1) * bufsize = (((lpWaveFormat->nAvgBytesPerSec / 3) - 1) / lpWaveFormat->nBlockAlign + 1) *
lpWaveFormat->nBlockAlign; lpWaveFormat->nBlockAlign;
waveHdr = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(WAVEHDR) + 2 * bufsize); waveHdr = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(WAVEHDR) + 2 * bufsize);
if (!waveHdr)
goto errCleanUp;
waveHdr[0].lpData = (char*)waveHdr + 2 * sizeof(WAVEHDR); waveHdr[0].lpData = (char*)waveHdr + 2 * sizeof(WAVEHDR);
waveHdr[1].lpData = (char*)waveHdr + 2 * sizeof(WAVEHDR) + bufsize; waveHdr[1].lpData = (char*)waveHdr + 2 * sizeof(WAVEHDR) + bufsize;
waveHdr[0].dwUser = waveHdr[1].dwUser = 0L; waveHdr[0].dwUser = waveHdr[1].dwUser = 0L;
...@@ -458,10 +463,10 @@ static DWORD WINAPI proc_PlaySound(LPVOID arg) ...@@ -458,10 +463,10 @@ static DWORD WINAPI proc_PlaySound(LPVOID arg)
errCleanUp: errCleanUp:
TRACE("Done playing=%s => %s!\n", debugstr_w(wps->pszSound), bRet ? "ok" : "ko"); TRACE("Done playing=%s => %s!\n", debugstr_w(wps->pszSound), bRet ? "ok" : "ko");
CloseHandle(s.hEvent);
HeapFree(GetProcessHeap(), 0, waveHdr);
HeapFree(GetProcessHeap(), 0, lpWaveFormat); HeapFree(GetProcessHeap(), 0, lpWaveFormat);
if (hWave) while (waveOutClose(hWave) == WAVERR_STILLPLAYING) Sleep(100); if (hWave) while (waveOutClose(hWave) == WAVERR_STILLPLAYING) Sleep(100);
CloseHandle(s.hEvent);
HeapFree(GetProcessHeap(), 0, waveHdr);
if (hmmio) mmioClose(hmmio, 0); if (hmmio) mmioClose(hmmio, 0);
PlaySound_Free(wps); PlaySound_Free(wps);
...@@ -509,16 +514,15 @@ static BOOL MULTIMEDIA_PlaySound(const void* pszSound, HMODULE hmod, DWORD fdwSo ...@@ -509,16 +514,15 @@ static BOOL MULTIMEDIA_PlaySound(const void* pszSound, HMODULE hmod, DWORD fdwSo
PlaySoundList = wps; PlaySoundList = wps;
LeaveCriticalSection(&WINMM_cs); LeaveCriticalSection(&WINMM_cs);
if (!pszSound || (fdwSound & SND_PURGE)) return TRUE; if (!wps) return TRUE;
if (fdwSound & SND_ASYNC) if (fdwSound & SND_ASYNC)
{ {
DWORD id;
HANDLE handle; HANDLE handle;
wps->bLoop = (fdwSound & SND_LOOP) ? TRUE : FALSE; wps->bLoop = (fdwSound & SND_LOOP) ? TRUE : FALSE;
if ((handle = CreateThread(NULL, 0, proc_PlaySound, wps, 0, &id)) != 0) { if ((handle = CreateThread(NULL, 0, proc_PlaySound, wps, 0, NULL)) != 0) {
wps->hThread = handle;
SetThreadPriority(handle, THREAD_PRIORITY_TIME_CRITICAL); SetThreadPriority(handle, THREAD_PRIORITY_TIME_CRITICAL);
CloseHandle(handle);
return TRUE; return TRUE;
} }
} }
......
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