summary refs log tree commit diff stats
path: root/lib/system
diff options
context:
space:
mode:
authorȘtefan Talpalaru <stefantalpalaru@yahoo.com>2019-05-14 21:47:14 +0200
committerAndreas Rumpf <rumpf_a@web.de>2019-05-14 21:47:14 +0200
commitfa3d19b4773648744834c67e5b2b9411e062b844 (patch)
tree2038794dda2ce4fff62e75ea9976b8575f73d978 /lib/system
parent0b41f26bd6cd9f50698e390ee708d5c95bb0afe5 (diff)
downloadNim-fa3d19b4773648744834c67e5b2b9411e062b844.tar.gz
cas(): use an "__atomic" builtin instead of the legacy "__sync" one (#11246)
"New code should always use the ‘__atomic’ builtins rather than the ‘__sync’ builtins." - https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html
Diffstat (limited to 'lib/system')
-rw-r--r--lib/system/atomics.nim3
1 files changed, 3 insertions, 0 deletions
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