|
27 | 27 |
|
28 | 28 | #pragma once |
29 | 29 |
|
| 30 | +#include "stdtypes.h" |
30 | 31 | #define LL_BOOST_ATOMICS 1 |
31 | 32 |
|
32 | | -//Internal definitions |
33 | | -#define NEEDS_APR_ATOMICS do_not_define_manually_thanks |
34 | | -#undef NEEDS_APR_ATOMICS |
35 | | - |
36 | | -//Prefer boost over stl over apr. |
37 | | - |
38 | 33 | #if LL_BOOST_ATOMICS |
39 | | -#include <boost/version.hpp> |
40 | 34 | #include <boost/atomic.hpp> |
41 | 35 | template<typename Type> |
42 | | -struct impl_atomic_type { typedef boost::atomic<Type> type; }; |
| 36 | +using LLAtomic32 = boost::atomic<Type>; |
43 | 37 | #elif LL_STD_ATOMICS |
44 | 38 | #include <atomic> |
45 | 39 | template<typename Type> |
46 | | -struct impl_atomic_type { typedef std::atomic<Type> type; }; |
47 | | -#else |
48 | | -#include "apr_atomic.h" |
49 | | -#define NEEDS_APR_ATOMICS |
50 | | -template <typename Type> class LLAtomic32 |
51 | | -{ |
52 | | -public: |
53 | | - LLAtomic32(void) { } |
54 | | - LLAtomic32(LLAtomic32 const& atom) { apr_uint32_t data = apr_atomic_read32(const_cast<apr_uint32_t*>(&atom.mData)); apr_atomic_set32(&mData, data); } |
55 | | - LLAtomic32(Type x) { apr_atomic_set32(&mData, static_cast<apr_uint32_t>(x)); } |
56 | | - LLAtomic32& operator=(LLAtomic32 const& atom) { apr_uint32_t data = apr_atomic_read32(const_cast<apr_uint32_t*>(&atom.mData)); apr_atomic_set32(&mData, data); return *this; } |
57 | | - |
58 | | - operator Type() const { apr_uint32_t data = apr_atomic_read32(const_cast<apr_uint32_t*>(&mData)); return static_cast<Type>(data); } |
59 | | - void operator=(Type x) { apr_atomic_set32(&mData, static_cast<apr_uint32_t>(x)); } |
60 | | - void operator-=(Type x) { apr_atomic_sub32(&mData, static_cast<apr_uint32_t>(x)); } |
61 | | - void operator+=(Type x) { apr_atomic_add32(&mData, static_cast<apr_uint32_t>(x)); } |
62 | | - Type operator++(int) { return apr_atomic_inc32(&mData); } // Type++ |
63 | | - Type operator++() { return apr_atomic_inc32(&mData); } // ++Type |
64 | | - Type operator--(int) { return apr_atomic_dec32(&mData); } // Type-- |
65 | | - Type operator--() { return apr_atomic_dec32(&mData); } // --Type |
66 | | - |
67 | | -private: |
68 | | - apr_uint32_t mData; |
69 | | -}; |
70 | | -#endif |
71 | | -#if !defined(NEEDS_APR_ATOMICS) |
72 | | -template <typename Type> class LLAtomic32 |
73 | | -{ |
74 | | -public: |
75 | | - LLAtomic32(void) { } |
76 | | - LLAtomic32(LLAtomic32 const& atom) { mData = Type(atom.mData); } |
77 | | - LLAtomic32(Type x) { mData = x; } |
78 | | - LLAtomic32& operator=(LLAtomic32 const& atom) { mData = Type(atom.mData); return *this; } |
79 | | - |
80 | | - operator Type() const { return mData; } |
81 | | - void operator=(Type x) { mData = x; } |
82 | | - void operator-=(Type x) { mData -= x; } |
83 | | - void operator+=(Type x) { mData += x; } |
84 | | - Type operator++(int) { return mData++; } // Type++ |
85 | | - Type operator++() { return ++mData; } // ++Type |
86 | | - Type operator--(int) { return mData--; } // Type-- |
87 | | - Type operator--() { return --mData; } // --Type |
88 | | - |
89 | | -private: |
90 | | - typename impl_atomic_type<Type>::type mData; |
91 | | -}; |
| 40 | +using LLAtomic32 = std::atomic<Type>; |
92 | 41 | #endif |
93 | 42 |
|
94 | 43 | typedef LLAtomic32<U32> LLAtomicU32; |
|
0 commit comments