Update windows to use platform independent watchdog implementation (nw)

This commit is contained in:
Miodrag Milanovic 2016-04-15 16:01:35 +02:00
parent bd04e5b17d
commit 37c94e3373
12 changed files with 32 additions and 114 deletions

View File

@ -44,6 +44,8 @@ function osdmodulesbuild()
files {
MAME_DIR .. "src/osd/osdnet.cpp",
MAME_DIR .. "src/osd/osdnet.h",
MAME_DIR .. "src/osd/watchdog.cpp",
MAME_DIR .. "src/osd/watchdog.h",
MAME_DIR .. "src/osd/modules/debugger/debug_module.h",
MAME_DIR .. "src/osd/modules/font/font_module.h",
MAME_DIR .. "src/osd/modules/midi/midi_module.h",

View File

@ -425,8 +425,6 @@ project ("osd_" .. _OPTIONS["osd"])
MAME_DIR .. "src/osd/sdl/window.h",
MAME_DIR .. "src/osd/modules/osdwindow.cpp",
MAME_DIR .. "src/osd/modules/osdwindow.h",
MAME_DIR .. "src/osd/sdl/watchdog.cpp",
MAME_DIR .. "src/osd/sdl/watchdog.h",
MAME_DIR .. "src/osd/modules/render/drawsdl.cpp",
}
files {

View File

@ -175,7 +175,8 @@ osd_common_t::osd_common_t(osd_options &options)
m_mouse_input(nullptr),
m_lightgun_input(nullptr),
m_joystick_input(nullptr),
m_output(nullptr)
m_output(nullptr),
m_watchdog(nullptr)
{
osd_output::push(this);
}
@ -420,6 +421,16 @@ void osd_common_t::init(running_machine &machine)
// ensure we get called on the way out
machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(osd_common_t::osd_exit), this));
/* now setup watchdog */
int watchdog_timeout = options.watchdog();
if (watchdog_timeout != 0)
{
m_watchdog = std::make_unique<watchdog>();
m_watchdog->setTimeout(watchdog_timeout);
}
}
@ -437,6 +448,11 @@ void osd_common_t::update(bool skip_redraw)
// irregular intervals in some circumstances (e.g., multi-screen games
// or games with asynchronous updates).
//
if (m_watchdog != NULL)
m_watchdog->reset();
update_slider_list();
}

View File

@ -14,6 +14,7 @@
#define MAME_OSD_LIB_OSDOBJ_COMMON_H
#include "osdepend.h"
#include "watchdog.h"
#include "modules/osdmodule.h"
#include "modules/font/font_module.h"
#include "modules/input/input_module.h"
@ -273,14 +274,15 @@ private:
}
protected:
sound_module* m_sound;
debug_module* m_debugger;
midi_module* m_midi;
input_module* m_keyboard_input;
input_module* m_mouse_input;
input_module* m_lightgun_input;
input_module* m_joystick_input;
sound_module* m_sound;
debug_module* m_debugger;
midi_module* m_midi;
input_module* m_keyboard_input;
input_module* m_mouse_input;
input_module* m_lightgun_input;
input_module* m_joystick_input;
output_module* m_output;
std::unique_ptr<watchdog> m_watchdog;
std::vector<ui_menu_item> m_sliders;
private:

View File

@ -3,7 +3,6 @@
#ifndef _osdsdl_h_
#define _osdsdl_h_
#include "watchdog.h"
#include "modules/lib/osdobj_common.h"
#include "modules/osdmodule.h"
#include "modules/font/font_module.h"
@ -168,8 +167,6 @@ private:
void extract_video_config();
sdl_options &m_options;
watchdog *m_watchdog;
};
//============================================================

View File

@ -53,8 +53,6 @@
#include <X11/Xutil.h>
#endif
#include "watchdog.h"
//============================================================
// OPTIONS
//============================================================
@ -250,7 +248,7 @@ static void output_oslog(const running_machine &machine, const char *buffer)
//============================================================
sdl_osd_interface::sdl_osd_interface(sdl_options &options)
: osd_common_t(options), m_options(options), m_watchdog(nullptr)
: osd_common_t(options), m_options(options)
{
}
@ -505,15 +503,7 @@ void sdl_osd_interface::init(running_machine &machine)
if (options().oslog())
machine.add_logerror_callback(output_oslog);
/* now setup watchdog */
int watchdog_timeout = options().watchdog();
if (watchdog_timeout != 0)
{
m_watchdog = auto_alloc(machine, watchdog);
m_watchdog->setTimeout(watchdog_timeout);
}
#ifdef SDLMAME_EMSCRIPTEN
SDL_EventState(SDL_TEXTINPUT, SDL_FALSE);

View File

@ -134,18 +134,13 @@ void sdl_monitor_info::refresh()
void sdl_osd_interface::update(bool skip_redraw)
{
sdl_window_info *window;
if (m_watchdog != NULL)
m_watchdog->reset();
update_slider_list();
osd_common_t::update(skip_redraw);
// if we're not skipping this redraw, update all windows
if (!skip_redraw)
{
// profiler_mark(PROFILER_BLIT);
for (window = sdl_window_list; window != NULL; window = window->m_next)
for (sdl_window_info *window = sdl_window_list; window != NULL; window = window->m_next)
window->update();
// profiler_mark(PROFILER_END);
}

View File

@ -166,10 +166,7 @@ osd_monitor_info *win_monitor_info::monitor_from_handle(HMONITOR hmonitor)
void windows_osd_interface::update(bool skip_redraw)
{
// ping the watchdog on each update
winmain_watchdog_ping();
update_slider_list();
osd_common_t::update(skip_redraw);
// if we're not skipping this redraw, update all windows
if (!skip_redraw)

View File

@ -280,10 +280,6 @@ static int timeresult = !TIMERR_NOERROR;
static TIMECAPS timecaps;
#endif
static HANDLE watchdog_reset_event;
static HANDLE watchdog_exit_event;
static HANDLE watchdog_thread;
static running_machine *g_current_machine;
@ -293,7 +289,6 @@ static running_machine *g_current_machine;
static BOOL WINAPI control_handler(DWORD type);
static int is_double_click_start(int argc);
static DWORD WINAPI watchdog_thread_entry(LPVOID lpParameter);
static LONG WINAPI exception_filter(struct _EXCEPTION_POINTERS *info);
@ -702,17 +697,6 @@ void windows_osd_interface::init(running_machine &machine)
timeBeginPeriod(timecaps.wPeriodMin);
#endif
// if a watchdog thread is requested, create one
int watchdog = options.watchdog();
if (watchdog != 0)
{
watchdog_reset_event = CreateEvent(nullptr, FALSE, FALSE, nullptr);
assert_always(watchdog_reset_event != nullptr, "Failed to create watchdog reset event");
watchdog_exit_event = CreateEvent(nullptr, TRUE, FALSE, nullptr);
assert_always(watchdog_exit_event != nullptr, "Failed to create watchdog exit event");
watchdog_thread = CreateThread(nullptr, 0, watchdog_thread_entry, (LPVOID)(FPTR)watchdog, 0, nullptr);
assert_always(watchdog_thread != nullptr, "Failed to create watchdog thread");
}
// create and start the profiler
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
@ -745,18 +729,6 @@ void windows_osd_interface::osd_exit()
osd_common_t::osd_exit();
// take down the watchdog thread if it exists
if (watchdog_thread != nullptr)
{
SetEvent(watchdog_exit_event);
WaitForSingleObject(watchdog_thread, INFINITE);
CloseHandle(watchdog_reset_event);
CloseHandle(watchdog_exit_event);
CloseHandle(watchdog_thread);
watchdog_reset_event = nullptr;
watchdog_exit_event = nullptr;
watchdog_thread = nullptr;
}
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
// stop the profiler
@ -777,55 +749,6 @@ void windows_osd_interface::osd_exit()
}
//============================================================
// watchdog_thread_entry
//============================================================
static DWORD WINAPI watchdog_thread_entry(LPVOID lpParameter)
{
DWORD timeout = (int)(FPTR)lpParameter * 1000;
while (TRUE)
{
HANDLE handle_list[2];
DWORD wait_result;
// wait for either a reset or an exit, or a timeout
handle_list[0] = watchdog_reset_event;
handle_list[1] = watchdog_exit_event;
wait_result = WaitForMultipleObjects(2, handle_list, FALSE, timeout);
// on a reset, just loop around and re-wait
if (wait_result == WAIT_OBJECT_0 + 0)
continue;
// on an exit, break out
if (wait_result == WAIT_OBJECT_0 + 1)
break;
// on a timeout, kill the process
if (wait_result == WAIT_TIMEOUT)
{
fprintf(stderr, "Terminating due to watchdog timeout\n");
fflush(stderr);
TerminateProcess(GetCurrentProcess(), -1);
}
}
return EXCEPTION_CONTINUE_SEARCH;
}
//============================================================
// winmain_watchdog_ping
//============================================================
void winmain_watchdog_ping(void)
{
// if we have a watchdog, reset it
if (watchdog_reset_event != nullptr)
SetEvent(watchdog_reset_event);
}
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)

View File

@ -337,8 +337,6 @@ extern int osd_num_processors;
// FUNCTION PROTOTYPES
//============================================================
// use this to ping the watchdog
void winmain_watchdog_ping(void);
void winmain_dump_stack();
#endif