Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
ScriptedAlgorithmWatchdog.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 <phosphortiles_export.h>
7
8#include <chrono>
9#include <condition_variable>
10#include <cstdint>
11#include <mutex>
12#include <thread>
13#include <unordered_map>
14
15namespace PhosphorTiles {
16
17class ScriptedAlgorithm;
18
53class PHOSPHORTILES_EXPORT ScriptedAlgorithmWatchdog
54{
55public:
58
66 void arm(ScriptedAlgorithm* algo, int timeoutMs);
67
75
91
92 // Non-copyable, non-movable — ownership is shared via std::shared_ptr
93 // (see class comment above for rationale). Move would invalidate the
94 // mutex / condvar / std::thread members.
99
100private:
101 struct Entry
102 {
103 std::chrono::steady_clock::time_point deadline;
104 uint64_t generation = 0;
105 };
106
107 void threadMain();
108
109 std::mutex m_mutex;
110 std::condition_variable m_cv;
111 std::unordered_map<ScriptedAlgorithm*, Entry> m_entries;
112 bool m_shutdown = false;
113 std::thread m_thread;
114};
115
116} // namespace PhosphorTiles
Per-loader watchdog for scripted algorithms.
Definition ScriptedAlgorithmWatchdog.h:54
ScriptedAlgorithmWatchdog(const ScriptedAlgorithmWatchdog &)=delete
void arm(ScriptedAlgorithm *algo, int timeoutMs)
Arm the watchdog for algo with a timeout of timeoutMs ms.
void unregister(ScriptedAlgorithm *algo)
Remove algo from the watchdog tracking map.
ScriptedAlgorithmWatchdog & operator=(const ScriptedAlgorithmWatchdog &)=delete
ScriptedAlgorithmWatchdog & operator=(ScriptedAlgorithmWatchdog &&)=delete
ScriptedAlgorithmWatchdog(ScriptedAlgorithmWatchdog &&)=delete
void disarm(ScriptedAlgorithm *algo)
Disarm the watchdog for algo.
Definition ScriptedAlgorithm.h:81
Definition AutotileEngine.h:71