From 13d8279e496b0fd21aadfbaa354f4a430e9f2c70 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Fri, 8 Jul 2016 16:47:06 +1000 Subject: MT6284 flush stdout/stderr before killing process --- src/osd/watchdog.cpp | 65 +++++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 31 deletions(-) (limited to 'src/osd/watchdog.cpp') 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 - 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(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; } -- cgit v1.2.3-70-g09d2