From 04f39105c5a418905da8b7657ca244d672c99d3b Mon Sep 17 00:00:00 2001 From: costan Date: Wed, 21 Mar 2018 09:26:49 -0700 Subject: [PATCH] Take for granted in port/atomic_pointer.h. C++11 requires . This lets us remove the header detection (LEVELDB_ATOMIC_PRESENT) and simplify port/atomic_pointer.h. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=189919098 --- CMakeLists.txt | 3 -- port/atomic_pointer.h | 80 ++++----------------------------------------------- port/port_config.h.in | 7 ----- 3 files changed, 5 insertions(+), 85 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f7c36a..ca43d7e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,9 +25,6 @@ test_big_endian(LEVELDB_IS_BIG_ENDIAN) include(CheckIncludeFile) check_include_file("unistd.h" HAVE_UNISTD_H) -include(CheckIncludeFileCXX) -check_include_file_cxx("atomic" LEVELDB_ATOMIC_PRESENT) - include(CheckLibraryExists) check_library_exists(crc32c crc32c_value "" HAVE_CRC32C) check_library_exists(snappy snappy_compress "" HAVE_SNAPPY) diff --git a/port/atomic_pointer.h b/port/atomic_pointer.h index 43dab2a..bb4e183 100644 --- a/port/atomic_pointer.h +++ b/port/atomic_pointer.h @@ -19,11 +19,9 @@ #define PORT_ATOMIC_POINTER_H_ #include -#ifdef LEVELDB_ATOMIC_PRESENT + #include -#elif defined(__APPLE__) -#include -#endif + #ifdef OS_WIN #include #endif @@ -55,11 +53,7 @@ namespace port { // Mac OS #elif defined(__APPLE__) inline void MemoryBarrier() { -#if defined(LEVELDB_ATOMIC_PRESENT) std::atomic_thread_fence(std::memory_order_seq_cst); -#else - OSMemoryBarrier(); -#endif // defined(LEVELDB_ATOMIC_PRESENT) } #define LEVELDB_HAVE_MEMORY_BARRIER @@ -124,7 +118,7 @@ inline void MemoryBarrier() { #endif -// AtomicPointer built using platform-specific MemoryBarrier() +// AtomicPointer built using platform-specific MemoryBarrier(). #if defined(LEVELDB_HAVE_MEMORY_BARRIER) class AtomicPointer { private: @@ -145,8 +139,8 @@ class AtomicPointer { } }; -// AtomicPointer based on -#elif defined(LEVELDB_ATOMIC_PRESENT) +// AtomicPointer based on C++11 . +#else class AtomicPointer { private: std::atomic rep_; @@ -167,70 +161,6 @@ class AtomicPointer { } }; -// Atomic pointer based on sparc memory barriers -#elif defined(__sparcv9) && defined(__GNUC__) -class AtomicPointer { - private: - void* rep_; - public: - AtomicPointer() { } - explicit AtomicPointer(void* v) : rep_(v) { } - inline void* Acquire_Load() const { - void* val; - __asm__ __volatile__ ( - "ldx [%[rep_]], %[val] \n\t" - "membar #LoadLoad|#LoadStore \n\t" - : [val] "=r" (val) - : [rep_] "r" (&rep_) - : "memory"); - return val; - } - inline void Release_Store(void* v) { - __asm__ __volatile__ ( - "membar #LoadStore|#StoreStore \n\t" - "stx %[v], [%[rep_]] \n\t" - : - : [rep_] "r" (&rep_), [v] "r" (v) - : "memory"); - } - inline void* NoBarrier_Load() const { return rep_; } - inline void NoBarrier_Store(void* v) { rep_ = v; } -}; - -// Atomic pointer based on ia64 acq/rel -#elif defined(__ia64) && defined(__GNUC__) -class AtomicPointer { - private: - void* rep_; - public: - AtomicPointer() { } - explicit AtomicPointer(void* v) : rep_(v) { } - inline void* Acquire_Load() const { - void* val ; - __asm__ __volatile__ ( - "ld8.acq %[val] = [%[rep_]] \n\t" - : [val] "=r" (val) - : [rep_] "r" (&rep_) - : "memory" - ); - return val; - } - inline void Release_Store(void* v) { - __asm__ __volatile__ ( - "st8.rel [%[rep_]] = %[v] \n\t" - : - : [rep_] "r" (&rep_), [v] "r" (v) - : "memory" - ); - } - inline void* NoBarrier_Load() const { return rep_; } - inline void NoBarrier_Store(void* v) { rep_ = v; } -}; - -// We have neither MemoryBarrier(), nor -#else -#error Please implement AtomicPointer for this platform. - #endif #undef LEVELDB_HAVE_MEMORY_BARRIER diff --git a/port/port_config.h.in b/port/port_config.h.in index 549f179..1934055 100644 --- a/port/port_config.h.in +++ b/port/port_config.h.in @@ -26,11 +26,4 @@ #cmakedefine01 LEVELDB_IS_BIG_ENDIAN #endif // !defined(LEVELDB_IS_BIG_ENDIAN) -// Define to 1 if you have the header. -// NOTE: was standardized in C++11, which will be required to build -// LevelDB soon. -#if !defined(LEVELDB_ATOMIC_PRESENT) -#cmakedefine01 LEVELDB_ATOMIC_PRESENT -#endif // !defined(LEVELDB_ATOMIC_PRESENT) - #endif // STORAGE_LEVELDB_PORT_PORT_CONFIG_H_ \ No newline at end of file