diff options
author | 2016-07-08 16:47:06 +1000 | |
---|---|---|
committer | 2016-07-08 16:47:06 +1000 | |
commit | 13d8279e496b0fd21aadfbaa354f4a430e9f2c70 (patch) | |
tree | dbc7136c66c43461b7dfb24bc451ba1ed5d76208 | |
parent | c0755dd46f34fc42812b0cdbc5f37b8af8fb97c4 (diff) |
MT6284 flush stdout/stderr before killing process
-rw-r--r-- | src/osd/modules/lib/osdlib_macosx.cpp | 5 | ||||
-rw-r--r-- | src/osd/modules/lib/osdlib_unix.cpp | 5 | ||||
-rw-r--r-- | src/osd/modules/lib/osdlib_win32.cpp | 5 | ||||
-rw-r--r-- | src/osd/watchdog.cpp | 65 | ||||
-rw-r--r-- | src/osd/watchdog.h | 36 |
5 files changed, 69 insertions, 47 deletions
diff --git a/src/osd/modules/lib/osdlib_macosx.cpp b/src/osd/modules/lib/osdlib_macosx.cpp index 18730ea70ff..94b935de08d 100644 --- a/src/osd/modules/lib/osdlib_macosx.cpp +++ b/src/osd/modules/lib/osdlib_macosx.cpp @@ -15,6 +15,7 @@ #include <signal.h> #include <dlfcn.h> +#include <cstdio> #include <iomanip> #include <memory> @@ -49,8 +50,10 @@ int osd_setenv(const char *name, const char *value, int overwrite) // osd_process_kill //============================================================ -void osd_process_kill(void) +void osd_process_kill() { + std::fflush(stdout); + std::fflush(stderr); kill(getpid(), SIGKILL); } diff --git a/src/osd/modules/lib/osdlib_unix.cpp b/src/osd/modules/lib/osdlib_unix.cpp index a504dec8aa3..054c4591f71 100644 --- a/src/osd/modules/lib/osdlib_unix.cpp +++ b/src/osd/modules/lib/osdlib_unix.cpp @@ -15,6 +15,7 @@ #include <signal.h> #include <dlfcn.h> +#include <cstdio> #include <iomanip> #include <memory> @@ -47,8 +48,10 @@ int osd_setenv(const char *name, const char *value, int overwrite) // osd_process_kill //============================================================ -void osd_process_kill(void) +void osd_process_kill() { + std::fflush(stdout); + std::fflush(stderr); kill(getpid(), SIGKILL); } diff --git a/src/osd/modules/lib/osdlib_win32.cpp b/src/osd/modules/lib/osdlib_win32.cpp index 06a979a7a77..015504f06dc 100644 --- a/src/osd/modules/lib/osdlib_win32.cpp +++ b/src/osd/modules/lib/osdlib_win32.cpp @@ -17,6 +17,7 @@ #include <unistd.h> #endif +#include <cstdio> #include <memory> // MAME headers @@ -98,8 +99,10 @@ int osd_setenv(const char *name, const char *value, int overwrite) // osd_process_kill //============================================================ -void osd_process_kill(void) +void osd_process_kill() { + std::fflush(stdout); + std::fflush(stderr); TerminateProcess(GetCurrentProcess(), -1); } diff --git a/src/osd/watchdog.cpp b/src/osd/watchdog.cpp index f963ef13f07..09f720b7fcc 100644 --- a/src/osd/watchdog.cpp +++ b/src/osd/watchdog.cpp @@ -15,50 +15,53 @@ #include "watchdog.h" #include "modules/lib/osdlib.h" -static void *watchdog_thread(void *param) -{ - osd_watchdog *thiz = (osd_watchdog *) param; +#include <cstdio> - while (TRUE) - { - if (thiz->event().wait(thiz->getTimeout())) - { - if (thiz->do_exit()) - break; - else - { - thiz->event().reset(); - continue; - } - } - else - { - fprintf(stderr, "Terminating due to watchdog timeout\n"); - osd_process_kill(); - } - } - return nullptr; -} -osd_watchdog::osd_watchdog(void) -: m_event(1,0) +osd_watchdog::osd_watchdog() + : m_timeout(60 * osd_ticks_per_second()) + , m_event(1, 0) + , m_do_exit() + , m_thread() { - m_do_exit = 0; - m_thread = new std::thread(watchdog_thread, this); - m_timeout = 60 * osd_ticks_per_second(); + m_thread.reset(new std::thread(&osd_watchdog::watchdog_thread, this)); } -osd_watchdog::~osd_watchdog(void) +osd_watchdog::~osd_watchdog() { m_do_exit = 1; m_event.set(); m_thread->join(); - delete m_thread; } void osd_watchdog::setTimeout(int timeout) { m_timeout = timeout * osd_ticks_per_second(); - this->reset(); + reset(); +} + +void *osd_watchdog::watchdog_thread(void *param) +{ + osd_watchdog *const thiz(reinterpret_cast<osd_watchdog *>(param)); + + while (true) + { + if (thiz->wait()) + { + if (thiz->do_exit()) + break; + else + thiz->clear_event(); + } + else + { + std::fflush(stdout); + std::fprintf(stderr, "Terminating due to watchdog timeout\n"); + std::fflush(stderr); + + osd_process_kill(); + } + } + return nullptr; } diff --git a/src/osd/watchdog.h b/src/osd/watchdog.h index 77cf3c77c7c..0076bc42c37 100644 --- a/src/osd/watchdog.h +++ b/src/osd/watchdog.h @@ -1,7 +1,9 @@ // license:BSD-3-Clause // copyright-holders:Olivier Galibert, R. Belmont -#ifndef _watchdog_h_ -#define _watchdog_h_ +#ifndef MAME_OSD_WATCHDOG_H +#define MAME_OSD_WATCHDOG_H +#pragma once + //============================================================ // // watchdog.h - watchdog handling @@ -11,26 +13,34 @@ //============================================================ #include "osdsync.h" + #include <atomic> +#include <cstdint> +#include <memory> #include <thread> + class osd_watchdog { public: - osd_watchdog(void); - ~osd_watchdog(void); - - void reset() { m_event.set(); } + osd_watchdog(); + ~osd_watchdog(); - osd_event & event(void) { return m_event; } - INT32 do_exit(void) const { return m_do_exit; } osd_ticks_t getTimeout(void) const { return m_timeout; } void setTimeout(int timeout); + + void reset() { m_event.set(); } + private: - osd_event m_event; - std::thread* m_thread; - std::atomic<INT32> m_do_exit; + static void *watchdog_thread(void *param); + + void clear_event() { m_event.reset(); } + bool wait() { return m_event.wait(getTimeout()); } + bool do_exit(void) const { return m_do_exit != 0; } - osd_ticks_t m_timeout; + osd_ticks_t m_timeout; + osd_event m_event; + std::atomic<std::int32_t> m_do_exit; + std::unique_ptr<std::thread> m_thread; }; -#endif +#endif // MAME_OSD_WATCHDOG_H |