Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
PhosphorScripting::LuauWatchdog Class Reference

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.

Detailed Description

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.

Constructor & Destructor Documentation

◆ LuauWatchdog() [1/2]

PhosphorScripting::LuauWatchdog::LuauWatchdog ( )

◆ ~LuauWatchdog()

PhosphorScripting::LuauWatchdog::~LuauWatchdog ( )

◆ LuauWatchdog() [2/2]

PhosphorScripting::LuauWatchdog::LuauWatchdog ( const LuauWatchdog & )
delete

Member Function Documentation

◆ arm()

void PhosphorScripting::LuauWatchdog::arm ( const void * key,
int timeoutMs )

Start a timeoutMs deadline for key.

No-op if key is unregistered or timeoutMs <= 0.

◆ disarm()

void PhosphorScripting::LuauWatchdog::disarm ( const void * key)

Cancel key's pending deadline.

◆ operator=()

LuauWatchdog & PhosphorScripting::LuauWatchdog::operator= ( const LuauWatchdog & )
delete

◆ registerFlag()

void PhosphorScripting::LuauWatchdog::registerFlag ( const void * key,
std::shared_ptr< std::atomic< bool > > flag )

Register key's interrupt flag. Idempotent; replaces an existing flag.

◆ unregister()

void PhosphorScripting::LuauWatchdog::unregister ( const void * key)

Remove key entirely. Safe to call from the engine destructor.


The documentation for this class was generated from the following file: