fix atomicarc increment (#23427)

The fix to the atomicArc looks to use `-1` as the check value from the
`SharedPtr` solution. However, it should be `-rcIncrement` since the
refcount is bit shifted in ARC/ORC.

I discovered this playing around doing atomic updates of refcounts in a
user library.

Related to https://github.com/nim-lang/Nim/issues/22711 

@ringabout I believe you ported the sharedptr fix?
This commit is contained in:
Jaremy Creechley
2024-03-25 11:59:18 +02:00
committed by GitHub
parent 33902d9dbb
commit 280f877145

View File

@@ -221,7 +221,7 @@ proc nimDecRefIsLast(p: pointer): bool {.compilerRtl, inl.} =
when defined(gcAtomicArc) and hasThreadSupport:
# `atomicDec` returns the new value
if atomicDec(cell.rc, rcIncrement) == -1:
if atomicDec(cell.rc, rcIncrement) == -rcIncrement:
result = true
when traceCollector:
cprintf("[ABOUT TO DESTROY] %p\n", cell)