summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/watchdog.cpp
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2016-07-08 16:47:06 +1000
committer Vas Crabb <vas@vastheman.com>2016-07-08 16:47:06 +1000
commit13d8279e496b0fd21aadfbaa354f4a430e9f2c70 (patch)
treedbc7136c66c43461b7dfb24bc451ba1ed5d76208 /src/osd/watchdog.cpp
parentc0755dd46f34fc42812b0cdbc5f37b8af8fb97c4 (diff)
MT6284 flush stdout/stderr before killing process
Diffstat (limited to 'src/osd/watchdog.cpp')
-rw-r--r--src/osd/watchdog.cpp65
1 files changed, 34 insertions, 31 deletions
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;
}