diff options
author | Chris Robinson <[email protected]> | 2008-02-03 00:28:00 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2008-02-03 00:28:00 -0800 |
commit | 4d6c292757b9aae20f915a11258f531e68353041 (patch) | |
tree | d8b61fa2cc867e5d38a8547814531dda0ad4510a /Alc/winmm.c | |
parent | 655a83c5c54c7e604f9d9f53fbf34bc85149d392 (diff) |
Fix race condition when starting winmm message poll thread
Diffstat (limited to 'Alc/winmm.c')
-rw-r--r-- | Alc/winmm.c | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/Alc/winmm.c b/Alc/winmm.c index 60f958cb..118db589 100644 --- a/Alc/winmm.c +++ b/Alc/winmm.c @@ -65,7 +65,7 @@ static void CALLBACK WaveInProc(HWAVEIN hDevice,UINT uMsg,DWORD_PTR dwInstance,D (void)hDevice; (void)dwParam2; - if ((uMsg==WIM_DATA) && (pDevice)) + if ((uMsg==WIM_DATA)) { // Decrement number of buffers in use pData->lWaveInBuffersCommitted--; @@ -228,10 +228,6 @@ static ALCboolean WinMMOpenCapture(ALCdevice *pDevice, const ALCchar *deviceName if (pData->hWaveInThreadEvent == NULL) goto failure; - pData->hWaveInThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)CaptureThreadProc, (LPVOID)pDevice, 0, &pData->ulWaveInThreadID); - if (pData->hWaveInThread == NULL) - goto failure; - // Allocate circular memory buffer for the captured audio pData->ulCapturedDataSize = SampleSize * wfexCaptureFormat.nBlockAlign; @@ -266,15 +262,32 @@ static ALCboolean WinMMOpenCapture(ALCdevice *pDevice, const ALCchar *deviceName pData->ulWriteCapturedDataPos = 0; pDevice->ExtraData = pData; + + pData->hWaveInThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)CaptureThreadProc, (LPVOID)pDevice, 0, &pData->ulWaveInThreadID); + if (pData->hWaveInThread == NULL) + goto failure; + return ALC_TRUE; failure: - if (pData->hWaveInThreadEvent) - CloseHandle(pData->hWaveInThreadEvent); + for (i=0;i<4;i++) + { + if(pData->WaveInBuffer[i].lpData) + { + waveInUnprepareHeader(pData->hWaveInHandle, &pData->WaveInBuffer[i], sizeof(WAVEHDR)); + free(pData->WaveInBuffer[i].lpData); + } + } + + free(pData->pCapturedSampleData); + if(pData->hWaveInHandle) + waveInClose(pData->hWaveInHandle); + if(pData->hWaveInThread) + CloseHandle(pData->hWaveInThread); if (pData->hWaveInHdrEvent) CloseHandle(pData->hWaveInHdrEvent); - if (pData->hWaveInHandle) - waveInClose(pData->hWaveInHandle); + if (pData->hWaveInThreadEvent) + CloseHandle(pData->hWaveInThreadEvent); free(pData); return ALC_FALSE; |