Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
LuauWatchdog.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include "phosphorscripting_export.h"
7
8#include <atomic>
9#include <chrono>
10#include <condition_variable>
11#include <cstdint>
12#include <memory>
13#include <mutex>
14#include <thread>
15#include <unordered_map>
16
17namespace PhosphorScripting {
18
37class PHOSPHORSCRIPTING_EXPORT LuauWatchdog
38{
39public:
42
43 LuauWatchdog(const LuauWatchdog&) = delete;
45
47 void registerFlag(const void* key, std::shared_ptr<std::atomic<bool>> flag);
48
50 void unregister(const void* key);
51
54 void arm(const void* key, int timeoutMs);
55
57 void disarm(const void* key);
58
59private:
60 struct Entry
61 {
62 std::shared_ptr<std::atomic<bool>> flag;
63 std::chrono::steady_clock::time_point deadline = std::chrono::steady_clock::time_point::max();
64 uint64_t generation = 0;
65 };
66
67 void threadMain();
68
69 std::unordered_map<const void*, Entry> m_entries;
70 std::thread m_thread;
71 std::mutex m_mutex;
72 std::condition_variable m_cv;
73 bool m_shutdown = false;
74};
75
76} // namespace PhosphorScripting
void registerFlag(const void *key, std::shared_ptr< std::atomic< bool > > flag)
Register key's interrupt flag. Idempotent; replaces an existing flag.
void disarm(const void *key)
Cancel key's pending deadline.
LuauWatchdog(const LuauWatchdog &)=delete
void arm(const void *key, int timeoutMs)
Start a timeoutMs deadline for key.
LuauWatchdog & operator=(const LuauWatchdog &)=delete
void unregister(const void *key)
Remove key entirely. Safe to call from the engine destructor.
Definition LuauEngine.h:19