Fix cas when using vcc/cpp and use the correct interlocked exchange for bool (#6735)

This commit is contained in:
Jörg Wollenschläger 2017-11-15 01:21:56 +09:00 • committed by Andreas Rumpf
commit eab7c88ce9

View file

@ -213,12 +213,20 @@ proc atomicDec*(memLoc: var int, x: int = 1): int =
result = memLoc result = memLoc
when defined(vcc): when defined(vcc):
proc interlockedCompareExchange64(p: pointer; exchange, comparand: int64): int64 when defined(cpp):
{.importc: "_InterlockedCompareExchange64", header: "<intrin.h>".} proc interlockedCompareExchange64(p: pointer; exchange, comparand: int64): int64
proc interlockedCompareExchange32(p: pointer; exchange, comparand: int32): int32 {.importcpp: "_InterlockedCompareExchange64(static_cast<NI64 volatile *>(#), #, #)", header: "<intrin.h>".}
{.importc: "_InterlockedCompareExchange", header: "<intrin.h>".} proc interlockedCompareExchange32(p: pointer; exchange, comparand: int32): int32
proc interlockedCompareExchange8(p: pointer; exchange, comparand: byte): byte {.importcpp: "_InterlockedCompareExchange(static_cast<NI volatile *>(#), #, #)", header: "<intrin.h>".}
{.importc: "_InterlockedCompareExchange64", header: "<intrin.h>".} proc interlockedCompareExchange8(p: pointer; exchange, comparand: byte): byte
{.importcpp: "_InterlockedCompareExchange8(static_cast<char volatile *>(#), #, #)", header: "<intrin.h>".}
else:
proc interlockedCompareExchange64(p: pointer; exchange, comparand: int64): int64
{.importc: "_InterlockedCompareExchange64", header: "<intrin.h>".}
proc interlockedCompareExchange32(p: pointer; exchange, comparand: int32): int32
{.importc: "_InterlockedCompareExchange", header: "<intrin.h>".}
proc interlockedCompareExchange8(p: pointer; exchange, comparand: byte): byte
{.importc: "_InterlockedCompareExchange8", header: "<intrin.h>".}
proc cas*[T: bool|int|ptr](p: ptr T; oldValue, newValue: T): bool = proc cas*[T: bool|int|ptr](p: ptr T; oldValue, newValue: T): bool =
when sizeof(T) == 8: when sizeof(T) == 8: