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
(cherry picked from commit 0992854)
  • Loading branch information
ringabout authored and narimiran committed Apr 24, 2023
1 parent 4857d92 commit 5cd2665
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 5cd2665

Please sign in to comment.