From fa3d19b4773648744834c67e5b2b9411e062b844 Mon Sep 17 00:00:00 2001 From: Ștefan Talpalaru Date: Tue, 14 May 2019 21:47:14 +0200 Subject: cas(): use an "__atomic" builtin instead of the legacy "__sync" one (#11246) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "New code should always use the ‘__atomic’ builtins rather than the ‘__sync’ builtins." - https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html --- lib/system/atomics.nim | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/system/atomics.nim') diff --git a/lib/system/atomics.nim b/lib/system/atomics.nim index 9111c072a..633348034 100644 --- a/lib/system/atomics.nim +++ b/lib/system/atomics.nim @@ -285,6 +285,9 @@ static int __tcc_cas(int *ptr, int oldVal, int newVal) {.importc: "__tcc_cas", nodecl.} proc cas*[T: bool|int|ptr](p: ptr T; oldValue, newValue: T): bool = tcc_cas(cast[ptr int](p), cast[int](oldValue), cast[int](newValue)) +elif declared(atomicCompareExchangeN): + proc cas*[T: bool|int|ptr](p: ptr T; oldValue, newValue: T): bool = + atomicCompareExchangeN(p, oldValue.unsafeAddr, newValue, false, ATOMIC_SEQ_CST, ATOMIC_SEQ_CST) else: # this is valid for GCC and Intel C++ proc cas*[T: bool|int|ptr](p: ptr T; oldValue, newValue: T): bool -- cgit 1.4.1-2-gfad0