mirror of https://github.com/odrling/Aegisub
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:
parent
324ce7dbff
commit
51a16f823e
|
@ -276,7 +276,8 @@ void DirectSoundPlayer::Stop(bool timerToo) {
|
||||||
if (thread) {
|
if (thread) {
|
||||||
if (thread->IsAlive()) {
|
if (thread->IsAlive()) {
|
||||||
thread->Stop();
|
thread->Stop();
|
||||||
thread->Wait();
|
// The thread is detached so it kills/deletes itself after being stopped
|
||||||
|
//thread->Wait();
|
||||||
}
|
}
|
||||||
thread = NULL;
|
thread = NULL;
|
||||||
}
|
}
|
||||||
|
@ -330,7 +331,7 @@ int64_t DirectSoundPlayer::GetCurrentPosition() {
|
||||||
|
|
||||||
//////////////////////
|
//////////////////////
|
||||||
// Thread constructor
|
// Thread constructor
|
||||||
DirectSoundPlayerThread::DirectSoundPlayerThread(DirectSoundPlayer *par) : wxThread(wxTHREAD_JOINABLE) {
|
DirectSoundPlayerThread::DirectSoundPlayerThread(DirectSoundPlayer *par) : wxThread(wxTHREAD_DETACHED) {
|
||||||
parent = par;
|
parent = par;
|
||||||
stopnotify = CreateEvent(NULL, true, false, NULL);
|
stopnotify = CreateEvent(NULL, true, false, NULL);
|
||||||
}
|
}
|
||||||
|
@ -346,6 +347,7 @@ DirectSoundPlayerThread::~DirectSoundPlayerThread() {
|
||||||
//////////////////////
|
//////////////////////
|
||||||
// Thread entry point
|
// Thread entry point
|
||||||
wxThread::ExitCode DirectSoundPlayerThread::Entry() {
|
wxThread::ExitCode DirectSoundPlayerThread::Entry() {
|
||||||
|
// Every thread that uses COM must initialise it
|
||||||
CoInitialize(0);
|
CoInitialize(0);
|
||||||
|
|
||||||
// Wake up thread every half second to fill buffer as needed
|
// Wake up thread every half second to fill buffer as needed
|
||||||
|
@ -388,6 +390,7 @@ wxThread::ExitCode DirectSoundPlayerThread::Entry() {
|
||||||
parent->playing = false;
|
parent->playing = false;
|
||||||
parent->buffer->Stop();
|
parent->buffer->Stop();
|
||||||
|
|
||||||
|
// And un-init COM since we inited it
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue