use atomicInc/atomicDec (#10906)

This commit is contained in:
Miran 2019-03-27 11:17:44 +01:00 • committed by Andreas Rumpf
commit d74179dde3

View file

@ -75,21 +75,20 @@ when defined(nimTypeNames):
outOfMemHook = oomhandler outOfMemHook = oomhandler
template decTypeSize(cell, t) = template decTypeSize(cell, t) =
# XXX this needs to use atomics for multithreaded apps!
when defined(nimTypeNames): when defined(nimTypeNames):
if t.kind in {tyString, tySequence}: if t.kind in {tyString, tySequence}:
let cap = cast[PGenericSeq](cellToUsr(cell)).space let cap = cast[PGenericSeq](cellToUsr(cell)).space
let size = if t.kind == tyString: cap+1+GenericSeqSize let size = if t.kind == tyString: cap+1+GenericSeqSize
else: addInt(mulInt(cap, t.base.size), GenericSeqSize) else: addInt(mulInt(cap, t.base.size), GenericSeqSize)
dec t.sizes, size+sizeof(Cell) atomicDec t.sizes, size+sizeof(Cell)
else: else:
dec t.sizes, t.base.size+sizeof(Cell) atomicDec t.sizes, t.base.size+sizeof(Cell)
dec t.instances atomicDec t.instances
template incTypeSize(typ, size) = template incTypeSize(typ, size) =
when defined(nimTypeNames): when defined(nimTypeNames):
inc typ.instances atomicInc typ.instances
inc typ.sizes, size+sizeof(Cell) atomicInc typ.sizes, size+sizeof(Cell)
proc dispose*(x: ForeignCell) = proc dispose*(x: ForeignCell) =
when hasThreadSupport: when hasThreadSupport: