Lock and unlock mutex in both wxSound threads using it
The code was completely broken as it locked the mutex in only one thread and then tried to unlock it in another one, which made no sense, didn't protect against anything and resulted in errors and assert failures. Fix this by locking and unlocking the mutex in both threads before accessing shared data or playing sound. Closes #17990.
This commit is contained in:
@@ -336,6 +336,7 @@ private:
|
|||||||
#if wxUSE_THREADS
|
#if wxUSE_THREADS
|
||||||
wxThread::ExitCode wxSoundAsyncPlaybackThread::Entry()
|
wxThread::ExitCode wxSoundAsyncPlaybackThread::Entry()
|
||||||
{
|
{
|
||||||
|
m_adapt->m_mutexRightToPlay.Lock();
|
||||||
m_adapt->m_backend->Play(m_data, m_flags & ~wxSOUND_ASYNC,
|
m_adapt->m_backend->Play(m_data, m_flags & ~wxSOUND_ASYNC,
|
||||||
&m_adapt->m_status);
|
&m_adapt->m_status);
|
||||||
|
|
||||||
@@ -361,6 +362,7 @@ bool wxSoundSyncOnlyAdaptor::Play(wxSoundData *data, unsigned flags,
|
|||||||
wxThread *th = new wxSoundAsyncPlaybackThread(this, data, flags);
|
wxThread *th = new wxSoundAsyncPlaybackThread(this, data, flags);
|
||||||
th->Create();
|
th->Create();
|
||||||
th->Run();
|
th->Run();
|
||||||
|
m_mutexRightToPlay.Unlock();
|
||||||
wxLogTrace(wxT("sound"), wxT("launched async playback thread"));
|
wxLogTrace(wxT("sound"), wxT("launched async playback thread"));
|
||||||
return true;
|
return true;
|
||||||
#else
|
#else
|
||||||
|
Reference in New Issue
Block a user