blob: fa7ead2222404a64586602f6cf430d9561b95ce0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
//============================================================
//
// watchdog.c - watchdog handling
//
// Copyright (c) 1996-2011, Nicola Salmoria and the MAME Team.
// Visit http://mamedev.org for licensing and usage restrictions.
//
// SDLMAME by Olivier Galibert and R. Belmont
//
//============================================================
#include "osdcomm.h"
#include "osdcore.h"
#include "eminline.h"
#include "watchdog.h"
#include "modules/lib/osdlib.h"
static void *watchdog_thread(void *param)
{
watchdog *thiz = (watchdog *) param;
while (TRUE)
{
if (osd_event_wait(thiz->event(), thiz->getTimeout()))
{
if (thiz->do_exit())
break;
else
{
osd_event_reset(thiz->event());
continue;
}
}
else
{
fprintf(stderr, "Terminating due to watchdog timeout\n");
osd_process_kill();
}
}
return NULL;
}
watchdog::watchdog(void)
{
m_do_exit = 0;
m_event = osd_event_alloc(1, 0);
m_thread = osd_thread_create(watchdog_thread, this);
m_timeout = 60 * osd_ticks_per_second();
}
watchdog::~watchdog(void)
{
atomic_exchange32(&m_do_exit, 1);
osd_event_set(m_event);
osd_thread_wait_free(m_thread);
osd_event_free(m_event);
}
void watchdog::setTimeout(int timeout)
{
m_timeout = timeout * osd_ticks_per_second();
this->reset();
}
|