Files
Aurora.3/code/datums/helper_datums/stack_end_detector.dm
Fluffy e867030c2e Update MC (#18112)
* sdf

* fsda

* fuck

* fuck2

* toolz

* sdaf

* sdfa

* saf

* sdfa

* sdfa

* sdf

* sdfa

* temp rename

* temp rename

* temp rename

* sdaf

* the pain is immensurable in the land of byond

* the curse of rah

* safd

* sadf

* sadf

* gf

* asf

* fssdfa

* sfd

* sadf

* sfda

* brah

* brah

* it's easier for you to fix this

* ffs

* brah

* brah
2024-01-06 17:03:57 +01:00

33 lines
1001 B
Plaintext

/**
Stack End Detector.
Can detect if a given code stack has exited, used by the mc for stack overflow detection.
**/
/datum/stack_end_detector
var/datum/weakref/_WF
var/datum/stack_canary/_canary
/datum/stack_end_detector/New()
_canary = new()
_WF = WEAKREF(_canary)
/** Prime the stack overflow detector.
Store the return value of this proc call in a proc level var.
Can only be called once.
**/
/datum/stack_end_detector/proc/prime_canary()
if (!_canary)
CRASH("Prime_canary called twice")
. = _canary
_canary = null
/// Returns true if the stack is still going. Calling before the canary has been primed also returns true
/datum/stack_end_detector/proc/check()
return !!_WF.resolve()
/// Stack canary. Will go away if the stack it was primed by is ended by byond for return or stack overflow reasons.
/datum/stack_canary
/// empty proc to avoid warnings about unused variables. Call this proc on your canary in the stack it's watching.
/datum/stack_canary/proc/use_variable()