|
46 | 46 | namespace leveldb { |
47 | 47 | namespace port { |
48 | 48 |
|
| 49 | +// AtomicPointer based on <cstdatomic> if available |
| 50 | +#if defined(LEVELDB_ATOMIC_PRESENT) |
| 51 | +class AtomicPointer { |
| 52 | + private: |
| 53 | + std::atomic<void*> rep_; |
| 54 | + public: |
| 55 | + AtomicPointer() { } |
| 56 | + explicit AtomicPointer(void* v) : rep_(v) { } |
| 57 | + inline void* Acquire_Load() const { |
| 58 | + return rep_.load(std::memory_order_acquire); |
| 59 | + } |
| 60 | + inline void Release_Store(void* v) { |
| 61 | + rep_.store(v, std::memory_order_release); |
| 62 | + } |
| 63 | + inline void* NoBarrier_Load() const { |
| 64 | + return rep_.load(std::memory_order_relaxed); |
| 65 | + } |
| 66 | + inline void NoBarrier_Store(void* v) { |
| 67 | + rep_.store(v, std::memory_order_relaxed); |
| 68 | + } |
| 69 | +}; |
| 70 | + |
| 71 | +#else |
| 72 | + |
49 | 73 | // Define MemoryBarrier() if available |
50 | 74 | // Windows on x86 |
51 | 75 | #if defined(OS_WIN) && defined(COMPILER_MSVC) && defined(ARCH_CPU_X86_FAMILY) |
@@ -142,28 +166,6 @@ class AtomicPointer { |
142 | 166 | } |
143 | 167 | }; |
144 | 168 |
|
145 | | -// AtomicPointer based on <cstdatomic> |
146 | | -#elif defined(LEVELDB_ATOMIC_PRESENT) |
147 | | -class AtomicPointer { |
148 | | - private: |
149 | | - std::atomic<void*> rep_; |
150 | | - public: |
151 | | - AtomicPointer() { } |
152 | | - explicit AtomicPointer(void* v) : rep_(v) { } |
153 | | - inline void* Acquire_Load() const { |
154 | | - return rep_.load(std::memory_order_acquire); |
155 | | - } |
156 | | - inline void Release_Store(void* v) { |
157 | | - rep_.store(v, std::memory_order_release); |
158 | | - } |
159 | | - inline void* NoBarrier_Load() const { |
160 | | - return rep_.load(std::memory_order_relaxed); |
161 | | - } |
162 | | - inline void NoBarrier_Store(void* v) { |
163 | | - rep_.store(v, std::memory_order_relaxed); |
164 | | - } |
165 | | -}; |
166 | | - |
167 | 169 | // Atomic pointer based on sparc memory barriers |
168 | 170 | #elif defined(__sparcv9) && defined(__GNUC__) |
169 | 171 | class AtomicPointer { |
@@ -229,7 +231,7 @@ class AtomicPointer { |
229 | 231 | #error Please implement AtomicPointer for this platform. |
230 | 232 |
|
231 | 233 | #endif |
232 | | - |
| 234 | +#endif |
233 | 235 | #undef LEVELDB_HAVE_MEMORY_BARRIER |
234 | 236 | #undef ARCH_CPU_X86_FAMILY |
235 | 237 | #undef ARCH_CPU_ARM_FAMILY |
|
0 commit comments