more arc improvements (#12690)

* ARC: bugfix for =destroy for inherited objects
* added code useful for debugging
This commit is contained in:
Andreas Rumpf 2019-11-20 14:34:05 +01:00 • committed by GitHub
commit 85ffcd80c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 5 deletions

View file

@ -68,6 +68,7 @@ proc nimIncRef(p: pointer) {.compilerRtl, inl.} =
atomicInc head(p).rc
else:
inc head(p).rc
#cprintf("[INCREF] %p\n", p)
proc nimRawDispose(p: pointer) {.compilerRtl.} =
when not defined(nimscript):
@ -113,13 +114,15 @@ proc nimDecRefIsLast(p: pointer): bool {.compilerRtl, inl.} =
if atomicLoadN(addr head(p).rc, ATOMIC_RELAXED) == 0:
result = true
else:
if atomicDec(head(p).rc) <= 0:
result = true
discard atomicDec(head(p).rc)
else:
if head(p).rc == 0:
result = true
#cprintf("[DESTROY] %p\n", p)
else:
dec head(p).rc
# According to Lins it's correct to do nothing else here.
#cprintf("[DeCREF] %p\n", p)
proc GC_unref*[T](x: ref T) =
## New runtime only supports this operation for 'ref T'.