22 #include "mythintrinsic.h" 24 #include <cppmyth_config.h> 25 #if __cplusplus >= 201103L 27 typedef std::atomic<int> counter_t;
28 #define GETVALUE(p) (p)->load() 29 #define INCREMENT(p) ((p)->fetch_add(1, std::memory_order_relaxed) + 1) 30 #define DECREMENT(p) ((p)->fetch_sub(1, std::memory_order_relaxed) - 1) 32 #elif defined _MSC_VER 33 #define WIN32_LEAN_AND_MEAN 35 typedef volatile LONG counter_t;
36 #define GETVALUE(p) (*(p)) 37 #define INCREMENT(p) InterlockedIncrement(p) 38 #define DECREMENT(p) InterlockedDecrement(p) 40 #elif defined __APPLE__ 41 #include <libkern/OSAtomic.h> 42 typedef volatile int32_t counter_t;
43 #define GETVALUE(p) (*(p)) 44 #define INCREMENT(p) OSAtomicIncrement32(p) 45 #define DECREMENT(p) OSAtomicDecrement32(p) 47 #elif defined HAS_BUILTIN_SYNC_ADD_AND_FETCH 48 typedef volatile int counter_t;
49 #define GETVALUE(p) (*(p)) 50 #define INCREMENT(p) __sync_add_and_fetch(p, 1) 51 #if defined HAS_BUILTIN_SYNC_SUB_AND_FETCH 52 #define DECREMENT(p) __sync_sub_and_fetch(p, 1) 54 #define DECREMENT(p) __sync_add_and_fetch(p, -1) 58 #include "private/atomic.h" 59 #ifndef ATOMIC_NOATOMIC 60 typedef Myth::atomic<int> counter_t;
61 #define GETVALUE(p) (p)->load() 62 #define INCREMENT(p) (p)->add_fetch(1) 63 #define DECREMENT(p) (p)->sub_fetch(1) 67 #elif defined USE_LOCKED 68 #include "mythlocked.h" 70 #define GETVALUE(p) (p)->Load() 71 #define INCREMENT(p) (p)->Add(1) 72 #define DECREMENT(p) (p)->Sub(1) 75 #error Atomic add/sub are not. Overcome using definition USE_LOCKED. 86 Counter(
int val) : counter(val) {}
90 IntrinsicCounter::IntrinsicCounter(
int val)
95 IntrinsicCounter::~IntrinsicCounter()
100 int IntrinsicCounter::GetValue()
102 return GETVALUE(&m_ptr->counter);
105 int IntrinsicCounter::Increment()
107 return INCREMENT(&m_ptr->counter);
110 int IntrinsicCounter::Decrement()
112 return DECREMENT(&m_ptr->counter);
This is the main namespace that encloses all public classes.