Correctly call CoUninitialize() on Cubeb helper class destruction.

This commit is contained in:
Admiral H. Curtiss 2022-11-27 03:58:16 +01:00
parent 3cdc6e3d4a
commit 64bb9ae9a9
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
4 changed files with 21 additions and 2 deletions

View File

@ -46,6 +46,7 @@ CubebStream::CubebStream()
Common::ScopeGuard sync_event_guard([&sync_event] { sync_event.Set(); });
auto result = ::CoInitializeEx(nullptr, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE);
m_coinit_success = result == S_OK;
m_should_couninit = result == S_OK || result == S_FALSE;
});
sync_event.Wait();
}
@ -137,11 +138,12 @@ CubebStream::~CubebStream()
cubeb_stream_stop(m_stream);
cubeb_stream_destroy(m_stream);
#ifdef _WIN32
if (m_coinit_success)
if (m_should_couninit)
{
m_coinit_success = false;
m_should_couninit = false;
CoUninitialize();
}
m_coinit_success = false;
});
sync_event.Wait();
#endif

View File

@ -37,6 +37,7 @@ private:
#ifdef _WIN32
Common::WorkQueueThread<std::function<void()>> m_work_queue;
bool m_coinit_success = false;
bool m_should_couninit = false;
#endif
static long DataCallback(cubeb_stream* stream, void* user_data, const void* /*input_buffer*/,

View File

@ -221,6 +221,7 @@ CEXIMic::CEXIMic(int index)
Common::ScopeGuard sync_event_guard([&sync_event] { sync_event.Set(); });
auto result = ::CoInitializeEx(nullptr, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE);
m_coinit_success = result == S_OK;
m_should_couninit = result == S_OK || result == S_FALSE;
});
sync_event.Wait();
#endif
@ -231,6 +232,20 @@ CEXIMic::CEXIMic(int index)
CEXIMic::~CEXIMic()
{
StreamTerminate();
#ifdef _WIN32
if (m_should_couninit)
{
Common::Event sync_event;
m_work_queue.EmplaceItem([this, &sync_event] {
Common::ScopeGuard sync_event_guard([&sync_event] { sync_event.Set(); });
m_should_couninit = false;
CoUninitialize();
});
sync_event.Wait();
}
m_coinit_success = false;
#endif
}
bool CEXIMic::IsPresent() const

View File

@ -104,6 +104,7 @@ private:
#ifdef _WIN32
Common::WorkQueueThread<std::function<void()>> m_work_queue;
bool m_coinit_success = false;
bool m_should_couninit = false;
#endif
};
} // namespace ExpansionInterface