mirror of
https://github.com/Ryujinx/libsoundio.git
synced 2024-12-22 23:25:34 +00:00
Use a different set of macros and types for atomics when compiled in C++
Previously, the `atomics.h` header relied solely on the presence of the C11 specific header `stdatomic.h`. Now, when compiled in C++, we use the `std::atomic` type family provided by the STL in C++11.
This commit is contained in:
parent
ff1af0e4cb
commit
af98891b4f
|
@ -11,6 +11,29 @@
|
|||
// Simple wrappers around atomic values so that the compiler will catch it if
|
||||
// I accidentally use operators such as +, -, += on them.
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <atomic>
|
||||
|
||||
struct SoundIoAtomicLong {
|
||||
std::atomic<long> x;
|
||||
};
|
||||
|
||||
struct SoundIoAtomicInt {
|
||||
std::atomic<int> x;
|
||||
};
|
||||
|
||||
struct SoundIoAtomicBool {
|
||||
std::atomic<bool> x;
|
||||
};
|
||||
|
||||
#define SOUNDIO_ATOMIC_LOAD(a) (a.x.load())
|
||||
#define SOUNDIO_ATOMIC_FETCH_ADD(a, delta) (a.x.fetch_add(delta))
|
||||
#define SOUNDIO_ATOMIC_STORE(a, value) (a.x.store(value))
|
||||
#define SOUNDIO_ATOMIC_EXCHANGE(a, value) (a.x.exchange(value))
|
||||
|
||||
#else
|
||||
|
||||
#include <stdatomic.h>
|
||||
|
||||
struct SoundIoAtomicLong {
|
||||
|
@ -31,3 +54,5 @@ struct SoundIoAtomicBool {
|
|||
#define SOUNDIO_ATOMIC_EXCHANGE(a, value) atomic_exchange(&a.x, value)
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue