Atomic inc/dec should use ATOMIC_SEQ_CST (#19212)

This commit is contained in:
flywind
2021-12-08 15:40:35 +08:00
committed by GitHub
parent 7806ec525e
commit 0992854941

View File

@@ -217,7 +217,7 @@ else:
proc atomicInc*(memLoc: var int, x: int = 1): int =
when someGcc and hasThreadSupport:
result = atomicAddFetch(memLoc.addr, x, ATOMIC_RELAXED)
result = atomicAddFetch(memLoc.addr, x, ATOMIC_SEQ_CST)
elif someVcc and hasThreadSupport:
result = addAndFetch(memLoc.addr, x)
inc(result, x)
@@ -228,9 +228,9 @@ proc atomicInc*(memLoc: var int, x: int = 1): int =
proc atomicDec*(memLoc: var int, x: int = 1): int =
when someGcc and hasThreadSupport:
when declared(atomicSubFetch):
result = atomicSubFetch(memLoc.addr, x, ATOMIC_RELAXED)
result = atomicSubFetch(memLoc.addr, x, ATOMIC_SEQ_CST)
else:
result = atomicAddFetch(memLoc.addr, -x, ATOMIC_RELAXED)
result = atomicAddFetch(memLoc.addr, -x, ATOMIC_SEQ_CST)
elif someVcc and hasThreadSupport:
result = addAndFetch(memLoc.addr, -x)
dec(result, x)