From 6c1a557a0f75549081c6e8702356987fa523bbda Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2017 17:21:23 +0100 Subject: [PATCH] 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. --- src/unix/sound.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/unix/sound.cpp b/src/unix/sound.cpp index 20646f2d7e..3a7c684a7a 100644 --- a/src/unix/sound.cpp +++ b/src/unix/sound.cpp @@ -336,6 +336,7 @@ private: #if wxUSE_THREADS wxThread::ExitCode wxSoundAsyncPlaybackThread::Entry() { + m_adapt->m_mutexRightToPlay.Lock(); m_adapt->m_backend->Play(m_data, m_flags & ~wxSOUND_ASYNC, &m_adapt->m_status); @@ -361,6 +362,7 @@ bool wxSoundSyncOnlyAdaptor::Play(wxSoundData *data, unsigned flags, wxThread *th = new wxSoundAsyncPlaybackThread(this, data, flags); th->Create(); th->Run(); + m_mutexRightToPlay.Unlock(); wxLogTrace(wxT("sound"), wxT("launched async playback thread")); return true; #else