Add FacetGuard

This commit is contained in:
Emery Hemingway 2024-03-12 12:33:23 +00:00
parent 82f2e8ee98
commit cd846d0d46
1 changed files with 20 additions and 0 deletions

View File

@ -685,3 +685,23 @@ proc run* =
except CatchableError as err:
stderr.writeLine "ioqueue continuation threw an error"
raise err
type FacetGuard* = object
facet: Facet
proc initGuard*(f: Facet): FacetGuard =
result.facet = f
inc result.facet.inertCheckPreventers
proc disarm*(g: var FacetGuard) =
if not g.facet.isNil:
assert g.facet.inertCheckPreventers > 0
dec g.facet.inertCheckPreventers
g.facet = nil
proc `=destroy`*(g: var FacetGuard) =
disarm(g)
proc `=copy`*(dst: var FacetGuard, src: FacetGuard) =
dst.facet = src.facet
inc dst.facet.inertCheckPreventers