Fix atomicInc under vcc, C++, amd64 (#5809)
Also, fixed inconsistent behaviour of atomicInc on vcc. Previously it would return the old value, while it must return the new value. Fixes: #5808
This commit is contained in:
parent
2e420dfa38
commit
77cadd07f9
1 changed files with 18 additions and 2 deletions
|
|
@ -165,6 +165,20 @@ when someGcc and hasThreadSupport:
|
||||||
|
|
||||||
template fence*() = atomicThreadFence(ATOMIC_SEQ_CST)
|
template fence*() = atomicThreadFence(ATOMIC_SEQ_CST)
|
||||||
elif defined(vcc) and hasThreadSupport:
|
elif defined(vcc) and hasThreadSupport:
|
||||||
|
when defined(cpp):
|
||||||
|
when sizeof(int) == 8:
|
||||||
|
proc addAndFetch*(p: ptr int, val: int): int {.
|
||||||
|
importcpp: "_InterlockedExchangeAdd64(static_cast<NI volatile *>(#), #)",
|
||||||
|
header: "<intrin.h>".}
|
||||||
|
else:
|
||||||
|
proc addAndFetch*(p: ptr int, val: int): int {.
|
||||||
|
importcpp: "_InterlockedExchangeAdd(static_cast<NI volatile *>(#), #)",
|
||||||
|
header: "<intrin.h>".}
|
||||||
|
else:
|
||||||
|
when sizeof(int) == 8:
|
||||||
|
proc addAndFetch*(p: ptr int, val: int): int {.
|
||||||
|
importc: "_InterlockedExchangeAdd64", header: "<intrin.h>".}
|
||||||
|
else:
|
||||||
proc addAndFetch*(p: ptr int, val: int): int {.
|
proc addAndFetch*(p: ptr int, val: int): int {.
|
||||||
importc: "_InterlockedExchangeAdd", header: "<intrin.h>".}
|
importc: "_InterlockedExchangeAdd", header: "<intrin.h>".}
|
||||||
|
|
||||||
|
|
@ -180,6 +194,7 @@ proc atomicInc*(memLoc: var int, x: int = 1): int =
|
||||||
result = atomic_add_fetch(memLoc.addr, x, ATOMIC_RELAXED)
|
result = atomic_add_fetch(memLoc.addr, x, ATOMIC_RELAXED)
|
||||||
elif defined(vcc) and hasThreadSupport:
|
elif defined(vcc) and hasThreadSupport:
|
||||||
result = addAndFetch(memLoc.addr, x)
|
result = addAndFetch(memLoc.addr, x)
|
||||||
|
inc(result, x)
|
||||||
else:
|
else:
|
||||||
inc(memLoc, x)
|
inc(memLoc, x)
|
||||||
result = memLoc
|
result = memLoc
|
||||||
|
|
@ -192,6 +207,7 @@ proc atomicDec*(memLoc: var int, x: int = 1): int =
|
||||||
result = atomic_add_fetch(memLoc.addr, -x, ATOMIC_RELAXED)
|
result = atomic_add_fetch(memLoc.addr, -x, ATOMIC_RELAXED)
|
||||||
elif defined(vcc) and hasThreadSupport:
|
elif defined(vcc) and hasThreadSupport:
|
||||||
result = addAndFetch(memLoc.addr, -x)
|
result = addAndFetch(memLoc.addr, -x)
|
||||||
|
dec(result, x)
|
||||||
else:
|
else:
|
||||||
dec(memLoc, x)
|
dec(memLoc, x)
|
||||||
result = memLoc
|
result = memLoc
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue