diff options
Diffstat (limited to 'src/osd/watchdog.cpp')
-rw-r--r-- | src/osd/watchdog.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/osd/watchdog.cpp b/src/osd/watchdog.cpp new file mode 100644 index 00000000000..8a86464cb56 --- /dev/null +++ b/src/osd/watchdog.cpp @@ -0,0 +1,64 @@ +// license:BSD-3-Clause +// copyright-holders:Olivier Galibert, R. Belmont +//============================================================ +// +// watchdog.c - watchdog handling +// +// SDLMAME by Olivier Galibert and R. Belmont +// +//============================================================ + +#include "osdcomm.h" +#include "osdcore.h" +#include "eminline.h" + +#include "watchdog.h" +#include "modules/lib/osdlib.h" + +static void *watchdog_thread(void *param) +{ + watchdog *thiz = (watchdog *) param; + + 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; +} + +watchdog::watchdog(void) +: m_event(1,0) +{ + m_do_exit = 0; + m_thread = new std::thread(watchdog_thread, this); + m_timeout = 60 * osd_ticks_per_second(); +} + +watchdog::~watchdog(void) +{ + m_do_exit = 1; + m_event.set(); + m_thread->join(); + delete m_thread; +} + +void watchdog::setTimeout(int timeout) +{ + m_timeout = timeout * osd_ticks_per_second(); + this->reset(); +} |