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:
Vadim Zeitlin
2017-11-07 17:21:23 +01:00
parent 6ebc56939f
commit 6c1a557a0f

View File

@@ -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