MT6284 flush stdout/stderr before killing process

This commit is contained in:
Vas Crabb 2016-07-08 16:47:06 +10:00
parent c0755dd46f
commit 13d8279e49
5 changed files with 71 additions and 49 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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)
osd_watchdog::osd_watchdog()
: m_timeout(60 * osd_ticks_per_second())
, m_event(1, 0)
, m_do_exit()
, m_thread()
{
m_thread.reset(new std::thread(&osd_watchdog::watchdog_thread, this));
}
osd_watchdog::~osd_watchdog()
{
m_do_exit = 1;
m_event.set();
m_thread->join();
}
void osd_watchdog::setTimeout(int timeout)
{
m_timeout = timeout * osd_ticks_per_second();
reset();
}
void *osd_watchdog::watchdog_thread(void *param)
{
osd_watchdog *const thiz(reinterpret_cast<osd_watchdog *>(param));
while (true)
{
if (thiz->event().wait(thiz->getTimeout()))
if (thiz->wait())
{
if (thiz->do_exit())
break;
else
{
thiz->event().reset();
continue;
}
thiz->clear_event();
}
else
{
fprintf(stderr, "Terminating due to watchdog timeout\n");
std::fflush(stdout);
std::fprintf(stderr, "Terminating due to watchdog timeout\n");
std::fflush(stderr);
osd_process_kill();
}
}
return nullptr;
}
osd_watchdog::osd_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();
}
osd_watchdog::~osd_watchdog(void)
{
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();
}

View File

@ -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);
osd_watchdog();
~osd_watchdog();
void reset() { m_event.set(); }
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);
private:
osd_event m_event;
std::thread* m_thread;
std::atomic<INT32> m_do_exit;
osd_ticks_t m_timeout;
void reset() { m_event.set(); }
private:
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_event m_event;
std::atomic<std::int32_t> m_do_exit;
std::unique_ptr<std::thread> m_thread;
};
#endif
#endif // MAME_OSD_WATCHDOG_H