wasapi:
- added calling thread id checks to match Pa_Initialize/Pa_Uninitialize in the same calling thread, if not the case then console warning will be thrown and CoUninitialize will not be called (preferring leak over uninitializing user-side COM)
This commit is contained in:
parent
8186129234
commit
43146e690e
1 changed files with 22 additions and 5 deletions
|
|
@ -545,7 +545,8 @@ static void _OnStreamStop(PaWasapiStream *stream);
|
|||
static void _FinishStream(PaWasapiStream *stream);
|
||||
|
||||
// Local statics
|
||||
static volatile BOOL g_bCOMInitialized = FALSE;
|
||||
static volatile BOOL g_WasapiCOMInit = FALSE;
|
||||
static volatile DWORD g_WasapiInitThread = 0;
|
||||
|
||||
// ------------------------------------------------------------------------------------------
|
||||
#define LogHostError(HRES) __LogHostError(HRES, __FUNCTION__, __FILE__, __LINE__)
|
||||
|
|
@ -957,7 +958,11 @@ PaError PaWasapi_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiInd
|
|||
return paUnanticipatedHostError;
|
||||
}
|
||||
if (hr != RPC_E_CHANGED_MODE)
|
||||
g_bCOMInitialized = TRUE;
|
||||
g_WasapiCOMInit = TRUE;
|
||||
|
||||
// Memorize calling thread id and report warning on Uninitialize if calling thread is different
|
||||
// as CoInitialize must match CoUninitialize in the same thread.
|
||||
g_WasapiInitThread = GetCurrentThreadId();
|
||||
|
||||
paWasapi = (PaWasapiHostApiRepresentation *)PaUtil_AllocateMemory( sizeof(PaWasapiHostApiRepresentation) );
|
||||
if (paWasapi == NULL)
|
||||
|
|
@ -1297,9 +1302,21 @@ static void Terminate( PaUtilHostApiRepresentation *hostApi )
|
|||
// Close AVRT
|
||||
CloseAVRT();
|
||||
|
||||
// Uninit COM
|
||||
if (g_bCOMInitialized)
|
||||
CoUninitialize();
|
||||
// Uninit COM (checking calling thread we won't unitialize user's COM if one is calling
|
||||
// Pa_Unitialize by mistake from not initializing thread)
|
||||
if (g_WasapiCOMInit)
|
||||
{
|
||||
DWORD calling_thread_id = GetCurrentThreadId();
|
||||
if (g_WasapiInitThread != calling_thread_id)
|
||||
{
|
||||
PRINT(("WASAPI: failed CoUninitializes calling thread[%d] does not match initializing thread[%d]\n",
|
||||
calling_thread_id, g_WasapiInitThread));
|
||||
}
|
||||
else
|
||||
{
|
||||
CoUninitialize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Reference in a new issue