[MIRROR] Add weakref support to qdel (#2742)

* Add weakref support to qdel (#56171)

qdel() should allow usage of weakrefs to avoid harddels on long duration qdel_in usage

* Add weakref support to qdel

Co-authored-by: spookydonut <github@spooksoftware.com>
This commit is contained in:
SkyratBot
2021-01-17 13:31:17 +01:00
committed by GitHub
parent 4615d8a0f1
commit 3499115feb
3 changed files with 9 additions and 3 deletions
+7 -1
View File
@@ -284,15 +284,21 @@ SUBSYSTEM_DEF(garbage)
///
/// Datums passed to this will be given a chance to clean up references to allow the GC to collect them.
/proc/qdel(datum/D, force=FALSE, ...)
if(isweakref(D))
var/datum/weakref/weakref = D
D = weakref.resolve()
if(!D)
return
if(!istype(D))
del(D)
return
var/datum/qdel_item/I = SSgarbage.items[D.type]
if (!I)
I = SSgarbage.items[D.type] = new /datum/qdel_item(D.type)
I.qdels++
if(isnull(D.gc_destroyed))
if (SEND_SIGNAL(D, COMSIG_PARENT_PREQDELETED, force)) // Give the components a chance to prevent their parent from being deleted
return