Skip to content

Commit

Permalink
Use stdatomic instead of gcc-internal atomics
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
hjelmn committed Dec 17, 2020
1 parent 1a08aa8 commit eed8a37
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions libusb/libusbi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

This comment has been minimized.

Copy link
@dickens

dickens Dec 17, 2020

Member

Any reason not to use atomic_fetch_sub()?

This comment has been minimized.

Copy link
@hjelmn

hjelmn Dec 17, 2020

Author Member

Just habit. Can change it if you want.

#endif

/* Internal abstractions for event handling and thread synchronization */
Expand Down
2 changes: 1 addition & 1 deletion libusb/version_nano.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define LIBUSB_NANO 11587
#define LIBUSB_NANO 11588

0 comments on commit eed8a37

Please sign in to comment.