diff --git a/src/atomics.h b/src/atomics.h index 6f0bcce..7e31cd3 100644 --- a/src/atomics.h +++ b/src/atomics.h @@ -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 + +struct SoundIoAtomicLong { + std::atomic x; +}; + +struct SoundIoAtomicInt { + std::atomic x; +}; + +struct SoundIoAtomicBool { + std::atomic 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 struct SoundIoAtomicLong { @@ -31,3 +54,5 @@ struct SoundIoAtomicBool { #define SOUNDIO_ATOMIC_EXCHANGE(a, value) atomic_exchange(&a.x, value) #endif + +#endif