From 9c6512ef9e24cace8e83a4df2e65b6d0f9ebffe3 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sat, 20 Feb 2010 17:30:22 +0000 Subject: [PATCH] =?UTF-8?q?(svn=20r19168)=20-Fix:=20under=20some=20circums?= =?UTF-8?q?tances=20timidity=20(via=20extmidi)=20would=20not=20shut=20down?= =?UTF-8?q?=20properly=20causing=20all=20kinds=20of=20trouble=20(e.g.=20bl?= =?UTF-8?q?ocked=20audio=20output).=20Try=20harder=20to=20shut=20down=20ti?= =?UTF-8?q?midity=20and=20first=20shut=20down=20the=20music=20so=20shut=20?= =?UTF-8?q?down=20order=20is=20the=20inverse=20of=20initialisation=20order?= =?UTF-8?q?.=20Based=20on=20a=20patch=20by=20Jind=C5=99ich=20Makovi=C4=8Dk?= =?UTF-8?q?a.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/driver.h | 13 +++++++------ src/music/extmidi.cpp | 23 ++++++++++++++++++++++- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/driver.h b/src/driver.h index cf86051de0..6b4ae7bc6d 100644 --- a/src/driver.h +++ b/src/driver.h @@ -28,12 +28,13 @@ public: virtual ~Driver() { } + /** The type of driver */ enum Type { - DT_BEGIN = 0, - DT_SOUND = 0, - DT_MUSIC, - DT_VIDEO, - DT_END, + DT_BEGIN = 0, ///< Helper for iteration + DT_MUSIC = 0, ///< A music driver, needs to be before sound to properly shut down extmidi forked music players + DT_SOUND, ///< A sound driver + DT_VIDEO, ///< A video driver + DT_END, ///< Helper for iteration }; virtual const char *GetName() const = 0; @@ -64,7 +65,7 @@ private: static const char *GetDriverTypeName(Driver::Type type) { - static const char * const driver_type_name[] = { "sound", "music", "video" }; + static const char * const driver_type_name[] = { "music", "sound", "video" }; return driver_type_name[type]; } diff --git a/src/music/extmidi.cpp b/src/music/extmidi.cpp index 48ee9d20eb..3842fc50cb 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 #include @@ -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__ */