Use stdatomic instead of gcc-internal atomics
authorNathan Hjelm <hjelmn@google.com>
Thu, 17 Dec 2020 03:57:57 +0000 (20:57 -0700)
committerNathan Hjelm <hjelmn@google.com>
Thu, 17 Dec 2020 03:57:57 +0000 (20:57 -0700)
The __atomic operations are internal to gcc and not necessarily supported
by all c11 compilers. Use the atomics in stdatomic instead.

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
libusb/libusbi.h
libusb/version_nano.h

index aea1bac94076b3c5d327426a9d30a7ec7e017d03..76566609016ef04847dbabaf6c4147254049212d 100644 (file)
@@ -103,11 +103,12 @@ typedef volatile LONG usbi_atomic_t;
 #define usbi_atomic_inc(a)     InterlockedIncrement((a))
 #define usbi_atomic_dec(a)     InterlockedDecrement((a))
 #else
-typedef long usbi_atomic_t;
-#define usbi_atomic_load(a)    __atomic_load_n((a), __ATOMIC_SEQ_CST)
-#define usbi_atomic_store(a, v)        __atomic_store_n((a), (v), __ATOMIC_SEQ_CST)
-#define usbi_atomic_inc(a)     __atomic_add_fetch((a), 1, __ATOMIC_SEQ_CST)
-#define usbi_atomic_dec(a)     __atomic_sub_fetch((a), 1, __ATOMIC_SEQ_CST)
+#include <stdatomic.h>
+typedef atomic_long usbi_atomic_t;
+#define usbi_atomic_load(a)    atomic_load((a))
+#define usbi_atomic_store(a, v)        atomic_store((a), (v))
+#define usbi_atomic_inc(a)     (atomic_fetch_add((a), 1) + 1)
+#define usbi_atomic_dec(a)     (atomic_fetch_add((a), -1) - 1)
 #endif
 
 /* Internal abstractions for event handling and thread synchronization */
index 692697101788dbe6fbfa90e69419c4d8c017955c..40532d3d6c922d6cd465872040b743332d3bbc91 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11587
+#define LIBUSB_NANO 11588