Skip to content

Commit

Permalink
Atomic inc/dec should use ATOMIC_SEQ_CST (#19212)
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout committed Dec 8, 2021
1 parent 7806ec5 commit 0992854
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/system/atomics.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 0992854

Please sign in to comment.