diff options
author | rubidium <rubidium@openttd.org> | 2010-02-20 17:30:22 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-02-20 17:30:22 +0000 |
commit | 9c6512ef9e24cace8e83a4df2e65b6d0f9ebffe3 (patch) | |
tree | ca902c2f28eb041bc978f04c3e31f73da585a8e9 /src/music | |
parent | e905cb57d8200b363dbab5732e090b222d2fd34a (diff) | |
download | openttd-9c6512ef9e24cace8e83a4df2e65b6d0f9ebffe3.tar.xz |
(svn r19168) -Fix: under some circumstances timidity (via extmidi) would not shut down properly causing all kinds of trouble (e.g. blocked audio output). Try harder to shut down timidity and first shut down the music so shut down order is the inverse of initialisation order. Based on a patch by Jindřich Makovička.
Diffstat (limited to 'src/music')
-rw-r--r-- | src/music/extmidi.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/music/extmidi.cpp b/src/music/extmidi.cpp index 48ee9d20e..3842fc50c 100644 --- a/src/music/extmidi.cpp +++ b/src/music/extmidi.cpp @@ -15,6 +15,7 @@ #include "../string_func.h" #include "../sound/sound_driver.hpp" #include "../video/video_driver.hpp" +#include "../gfx_func.h" #include "extmidi.h" #include <fcntl.h> #include <sys/types.h> @@ -108,7 +109,27 @@ void MusicDriver_ExtMidi::DoPlay() void MusicDriver_ExtMidi::DoStop() { - if (this->pid != -1) kill(this->pid, SIGTERM); + if (this->pid <= 0) return; + + /* First try to gracefully stop for about five seconds; + * 5 seconds = 5000 milliseconds, 10 ms per cycle => 500 cycles. */ + for (int i = 0; i < 500; i++) { + kill(this->pid, SIGTERM); + if (waitpid(this->pid, NULL, WNOHANG) == this->pid) { + /* It has shut down, so we are done */ + this->pid = -1; + return; + } + /* Wait 10 milliseconds. */ + CSleep(10); + } + + DEBUG(driver, 0, "extmidi: gracefully stopping failed, trying the hard way"); + /* Gracefully stopping failed. Do it the hard way + * and wait till the process finally died. */ + kill(this->pid, SIGKILL); + waitpid(this->pid, NULL, 0); + this->pid = -1; } #endif /* __MORPHOS__ */ |