Yet another attempt to fix #521, 'Cannot wait for thread termination' in rare cases with the DirectSound audio player.

Make the playback thread detached so it will kill itself when it has run to end, instead of having to wait for it. This way it is never required to wait for the thread. When the thread has been signalled to stop it is simply abandoned and left to die for itself.

Originally committed to SVN as r2201.
This commit is contained in:
Niels Martin Hansen 2008-06-15 12:59:49 +00:00
parent 324ce7dbff
commit 51a16f823e
1 changed files with 5 additions and 2 deletions

View File

@ -276,7 +276,8 @@ void DirectSoundPlayer::Stop(bool timerToo) {
if (thread) {
if (thread->IsAlive()) {
thread->Stop();
thread->Wait();
// The thread is detached so it kills/deletes itself after being stopped
//thread->Wait();
}
thread = NULL;
}
@ -330,7 +331,7 @@ int64_t DirectSoundPlayer::GetCurrentPosition() {
//////////////////////
// Thread constructor
DirectSoundPlayerThread::DirectSoundPlayerThread(DirectSoundPlayer *par) : wxThread(wxTHREAD_JOINABLE) {
DirectSoundPlayerThread::DirectSoundPlayerThread(DirectSoundPlayer *par) : wxThread(wxTHREAD_DETACHED) {
parent = par;
stopnotify = CreateEvent(NULL, true, false, NULL);
}
@ -346,6 +347,7 @@ DirectSoundPlayerThread::~DirectSoundPlayerThread() {
//////////////////////
// Thread entry point
wxThread::ExitCode DirectSoundPlayerThread::Entry() {
// Every thread that uses COM must initialise it
CoInitialize(0);
// Wake up thread every half second to fill buffer as needed
@ -388,6 +390,7 @@ wxThread::ExitCode DirectSoundPlayerThread::Entry() {
parent->playing = false;
parent->buffer->Stop();
// And un-init COM since we inited it
CoUninitialize();
return 0;
}