c373527851
--HG-- rename : public/amtl/ke_allocator_policies.h => public/amtl/am-allocator-policies.h rename : public/amtl/ke_inline_list.h => public/amtl/am-inline-list.h rename : public/amtl/ke_thread_posix.h => public/amtl/am-thread-posix.h rename : public/amtl/ke_thread_utils.h => public/amtl/am-thread-utils.h rename : public/amtl/ke_thread_windows.h => public/amtl/am-thread-windows.h rename : public/amtl/ke_utility.h => public/amtl/am-utility.h rename : public/amtl/ke_vector.h => public/amtl/am-vector.h
62 lines
1.6 KiB
C++
62 lines
1.6 KiB
C++
// vim: set ts=8 sts=2 sw=2 tw=99 et:
|
|
//
|
|
// This file is part of SourcePawn.
|
|
//
|
|
// SourcePawn is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// SourcePawn is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with SourcePawn. If not, see <http://www.gnu.org/licenses/>.
|
|
#ifndef _include_sourcepawn_watchdog_timer_posix_h_
|
|
#define _include_sourcepawn_watchdog_timer_posix_h_
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <am-thread-utils.h>
|
|
|
|
typedef bool (*WatchdogCallback)();
|
|
|
|
class WatchdogTimer : public ke::IRunnable
|
|
{
|
|
public:
|
|
WatchdogTimer();
|
|
~WatchdogTimer();
|
|
|
|
bool Initialize(size_t timeout_ms);
|
|
void Shutdown();
|
|
|
|
// Called from main thread.
|
|
bool NotifyTimeoutReceived();
|
|
bool HandleInterrupt();
|
|
|
|
private:
|
|
// Watchdog thread.
|
|
void Run();
|
|
|
|
private:
|
|
bool terminate_;
|
|
size_t timeout_ms_;
|
|
ke::ThreadId mainthread_;
|
|
|
|
ke::AutoPtr<ke::Thread> thread_;
|
|
ke::ConditionVariable cv_;
|
|
|
|
// Accessed only on the watchdog thread.
|
|
uintptr_t last_frame_id_;
|
|
bool second_timeout_;
|
|
|
|
// Accessed only on the main thread.
|
|
bool timedout_;
|
|
};
|
|
|
|
extern WatchdogTimer g_WatchdogTimer;
|
|
|
|
#endif // _include_sourcepawn_watchdog_timer_posix_h_
|