summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/watchdog.h
blob: 0076bc42c37b468a90d63e43f8e2e4cd1880d4a4 (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
// license:BSD-3-Clause
// copyright-holders:Olivier Galibert, R. Belmont
#ifndef MAME_OSD_WATCHDOG_H
#define MAME_OSD_WATCHDOG_H
#pragma once

//============================================================
//
//  watchdog.h - watchdog handling
//
//  SDLMAME by Olivier Galibert and R. Belmont
//
//============================================================

#include "osdsync.h"

#include <atomic>
#include <cstdint>
#include <memory>
#include <thread>


class osd_watchdog
{
public:
	osd_watchdog();
	~osd_watchdog();

	osd_ticks_t     getTimeout(void) const { return m_timeout; }
	void            setTimeout(int 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 // MAME_OSD_WATCHDOG_H