26#ifndef WATER_ATOMIC_H_INCLUDED
27#define WATER_ATOMIC_H_INCLUDED
35# define WIN32_LEAN_AND_MEAN 1
45# pragma clang diagnostic push
46# pragma clang diagnostic ignored "-Weffc++"
47#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
48# pragma GCC diagnostic push
49# pragma GCC diagnostic ignored "-Weffc++"
50#elif defined(_MSC_VER)
51# pragma warning (push)
52# pragma warning (disable: 4311)
54# pragma intrinsic (_InterlockedExchange, \
55 _InterlockedExchange64, \
56 _InterlockedExchangeAdd, \
57 _InterlockedExchangeAdd64, \
58 _InterlockedIncrement, \
59 _InterlockedIncrement64, \
60 _InterlockedDecrement, \
61 _InterlockedDecrement64, \
62 _InterlockedCompareExchange, \
63 _InterlockedCompareExchange64, \
66# pragma intrinsic (_InterlockedExchange, \
67 _InterlockedExchangeAdd, \
68 _InterlockedIncrement, \
69 _InterlockedDecrement, \
70 _InterlockedCompareExchange, \
71 _InterlockedCompareExchange64, \
76#if defined(CARLA_OS_64BIT) || !defined(_MSC_VER)
77# define WATER_ATOMIC_64_SUPPORTED
81# define WATER_ALIGN_SIZE 8
83# define WATER_ALIGN_SIZE 4
93template <
typename Type>
105 :
value (initialValue)
111 :
value (other.get())
118#ifdef CARLA_PROPER_CPP11_SUPPORT
207 mutable volatile Type
value;
210 template <
typename Dest,
typename Source>
226 template <
typename ValueType>
229 return sizeof (ValueType) == 1 ? (ValueType) -(
signed char)
n
230 : (
sizeof (ValueType) == 2 ? (ValueType) -(short)
n
231 : (
sizeof (ValueType) == 4 ? (ValueType) -(
int)
n
232 : ((ValueType) -(
int64)
n)));
236 template <
typename Po
interType>
247 #ifdef CARLA_PROPER_CPP11_SUPPORT
251 return castFromLong (_InterlockedExchangeAdd (
reinterpret_cast<volatile long*
> (&
value), 0));
260 #ifdef CARLA_PROPER_CPP11_SUPPORT
264 return castFromLong (_InterlockedExchangeAdd (
reinterpret_cast<volatile long*
> (&
value), 0));
270#ifdef WATER_ATOMIC_64_SUPPORTED
274 #ifdef CARLA_PROPER_CPP11_SUPPORT
287 #ifdef CARLA_PROPER_CPP11_SUPPORT
302 return castFromLong (_InterlockedExchange (
reinterpret_cast<volatile long*
> (&
value), castToLong (newValue)));
308 return castFromLong (_InterlockedExchange (
reinterpret_cast<volatile long*
> (&
value), castToLong (newValue)));
314 return castFromLong (_InterlockedExchangeAdd (
reinterpret_cast<volatile long*
> (&
value), castToLong (amountToAdd)));
320 return castFromLong (_InterlockedExchangeAdd (
reinterpret_cast<volatile long*
> (&
value), castToLong (amountToAdd)));
326 return castFromLong (_InterlockedIncrement (
reinterpret_cast<volatile long*
> (&
value)));
332 return castFromLong (_InterlockedIncrement (
reinterpret_cast<volatile long*
> (&
value)));
338 return castFromLong (_InterlockedDecrement (
reinterpret_cast<volatile long*
> (&
value)));
344 return castFromLong (_InterlockedDecrement (
reinterpret_cast<volatile long*
> (&
value)));
347# ifndef CARLA_OS_64BIT
351 return castFrom64Bit (_InterlockedCompareExchange64 (
reinterpret_cast<volatile int64*
> (&
value), castTo64Bit (
value), castTo64Bit (newValue)));
357 return castFrom64Bit (_InterlockedCompareExchange64 (
reinterpret_cast<volatile int64*
> (&
value), castTo64Bit (
value), castTo64Bit (newValue)));
363 return castFrom64Bit (_InterlockedExchange64 (
reinterpret_cast<volatile int64*
> (&
value), castTo64Bit (newValue)));
369 return castFrom64Bit (_InterlockedExchange64 (
reinterpret_cast<volatile int64*
> (&
value), castTo64Bit (newValue)));
375 return castFrom64Bit (_InterlockedExchangeAdd64 (
reinterpret_cast<volatile int64*
> (&
value), castTo64Bit (amountToAdd)));
381 return castFrom64Bit (_InterlockedExchangeAdd64 (
reinterpret_cast<volatile int64*
> (&
value), castTo64Bit (amountToAdd)));
387 return castFrom64Bit (_InterlockedIncrement64 (
reinterpret_cast<volatile int64*
> (&
value)));
393 return castFrom64Bit (_InterlockedIncrement64 (
reinterpret_cast<volatile int64*
> (&
value)));
399 return castFrom64Bit (_InterlockedDecrement64 (
reinterpret_cast<volatile int64*
> (&
value)));
405 return castFrom64Bit (_InterlockedDecrement64 (
reinterpret_cast<volatile int64*
> (&
value)));
409template <
typename Type>
412 Type currentVal =
value;
417template <
typename Type>
420 return (Type) __sync_add_and_fetch (&
value, amountToAdd);
423template <
typename Type>
426 return sizeof (Type) == 4 ? (Type) __sync_add_and_fetch (&
value, (Type) 1)
427 : (Type) __sync_add_and_fetch ((
volatile int64*) &
value, 1);
430template <
typename Type>
433 return sizeof (Type) == 4 ? (Type) __sync_add_and_fetch (&
value, (Type) -1)
434 : (Type) __sync_add_and_fetch ((
volatile int64*) &
value, -1);
438template <
typename Type>
444template <
typename Type>
455template <
typename Type>
467template <
typename Type>
473 __sync_synchronize();
477#if defined(__clang__)
478# pragma clang diagnostic pop
479#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
480# pragma GCC diagnostic pop
481#elif defined(_MSC_VER)
482# pragma warning (pop)
#define noexcept
Definition DistrhoDefines.h:72
uint32_t uint32
Definition basics.h:90
static void memoryBarrier() noexcept
Definition Atomic.h:468
Type operator++() noexcept
Definition Atomic.h:424
static Type castFromLong(long value) noexcept
Definition Atomic.h:217
Type operator--() noexcept
Definition Atomic.h:431
Type operator+=(Type amountToAdd) noexcept
Definition Atomic.h:418
static int64 castTo64Bit(Type value) noexcept
Definition Atomic.h:219
static Type castFrom32Bit(uint32 value) noexcept
Definition Atomic.h:215
Type exchange(Type value) noexcept
Definition Atomic.h:410
void set(Type newValue) noexcept
Definition Atomic.h:134
int compareAndSetValue(int newValue, int valueToCompare) noexcept
Definition Atomic.h:456
static long castToLong(Type value) noexcept
Definition Atomic.h:220
Atomic() noexcept
Definition Atomic.h:98
Atomic & operator=(const Atomic &other) noexcept
Definition Atomic.h:128
static int32 castTo32Bit(Type value) noexcept
Definition Atomic.h:218
bool compareAndSetBool(int newValue, int valueToCompare) noexcept
Definition Atomic.h:445
ValueType negateValue(ValueType n) noexcept
Definition Atomic.h:227
Type operator-=(Type amountToSubtract) noexcept
Definition Atomic.h:439
Atomic(const Type initialValue) noexcept
Definition Atomic.h:104
static Type castFrom64Bit(uint64 value) noexcept
Definition Atomic.h:216
~Atomic() noexcept
Definition Atomic.h:116
static Dest castTo(Source value) noexcept
Definition Atomic.h:211
static Type castFrom64Bit(int64 value) noexcept
Definition Atomic.h:214
PointerType * negateValue(PointerType *n) noexcept
Definition Atomic.h:237
static Type castFrom32Bit(int32 value) noexcept
Definition Atomic.h:213
__attribute__((aligned(WATER_ALIGN_SIZE))) mutable volatile Type value
Atomic(const Atomic &other) noexcept
Definition Atomic.h:110
Type get() const noexcept
unsigned d
Definition inflate.c:940
struct huft * u[BMAX]
Definition inflate.c:1583
unsigned s
Definition inflate.c:1555
static PuglViewHint int value
Definition pugl.h:1708
#define static_wassert(expression)
Definition AudioSampleBuffer.h:33
unsigned int uint32
Definition water.h:98
unsigned long long uint64
Definition water.h:102
int pointer_sized_int
Definition water.h:111
String & operator+=(String &s1, const NewLine &)
Definition NewLine.h:71
long long int64
Definition water.h:100
signed int int32
Definition water.h:96
int n
Definition crypt.c:458
typedef int(UZ_EXP MsgFn)()
#define const
Definition zconf.h:137