mirror of
https://github.com/holub/mame
synced 2025-04-21 07:52:35 +03:00
MT6284 flush stdout/stderr before killing process
This commit is contained in:
parent
c0755dd46f
commit
13d8279e49
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user