One supervisor thread that interrupts runaway scripts across many engines. More...
#include <PhosphorScripting/LuauWatchdog.h>
Public Member Functions | |
| LuauWatchdog () | |
| ~LuauWatchdog () | |
| LuauWatchdog (const LuauWatchdog &)=delete | |
| LuauWatchdog & | operator= (const LuauWatchdog &)=delete |
| void | registerFlag (const void *key, std::shared_ptr< std::atomic< bool > > flag) |
Register key's interrupt flag. Idempotent; replaces an existing flag. | |
| void | unregister (const void *key) |
Remove key entirely. Safe to call from the engine destructor. | |
| void | arm (const void *key, int timeoutMs) |
Start a timeoutMs deadline for key. | |
| void | disarm (const void *key) |
Cancel key's pending deadline. | |
One supervisor thread that interrupts runaway scripts across many engines.
Each LuauEngine registers a shared interrupt flag keyed by its own address. On arm the watchdog records a deadline; if the deadline passes before disarm, the watchdog sets *flag = true. The engine's interrupt callback (running on the VM thread at the next safepoint) reads the flag and unwinds via luaL_error.
Crucially the watchdog only ever writes a std::shared_ptr<std::atomic<bool>> it co-owns — it never touches the engine or its lua_State. A late write racing engine teardown is therefore safe (the atomic outlives the engine via the shared_ptr), which removes the use-after-free lock-discipline a setInterrupted-style watchdog needs.
One watchdog may be shared (via std::shared_ptr) by every engine in a composition root, so N engines cost one supervisor thread, not N.
| PhosphorScripting::LuauWatchdog::LuauWatchdog | ( | ) |
| PhosphorScripting::LuauWatchdog::~LuauWatchdog | ( | ) |
|
delete |
| void PhosphorScripting::LuauWatchdog::arm | ( | const void * | key, |
| int | timeoutMs ) |
Start a timeoutMs deadline for key.
No-op if key is unregistered or timeoutMs <= 0.
| void PhosphorScripting::LuauWatchdog::disarm | ( | const void * | key | ) |
Cancel key's pending deadline.
|
delete |
| void PhosphorScripting::LuauWatchdog::registerFlag | ( | const void * | key, |
| std::shared_ptr< std::atomic< bool > > | flag ) |
Register key's interrupt flag. Idempotent; replaces an existing flag.
| void PhosphorScripting::LuauWatchdog::unregister | ( | const void * | key | ) |
Remove key entirely. Safe to call from the engine destructor.