From: Kefu Chai Date: Wed, 25 Apr 2018 02:31:51 +0000 (+0800) Subject: port_posix: use new(size, std::align_val_t) for aligned_alloc X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c8de10cd2746e5b65400618120ccecc6b97417d6;p=rocksdb.git port_posix: use new(size, std::align_val_t) for aligned_alloc to workaround issue of http://tracker.ceph.com/issues/21422 . and by using C++17, we can use this new "new" operator. and to be consistent with the C++17 consumer of this library. Signed-off-by: Kefu Chai --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 18f89694..c55e091d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -169,7 +169,7 @@ else() if(MINGW) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-format") endif() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -fno-omit-frame-pointer") include(CheckCXXCompilerFlag) diff --git a/port/port_posix.cc b/port/port_posix.cc index 2408beeb..6e9ea645 100644 --- a/port/port_posix.cc +++ b/port/port_posix.cc @@ -188,6 +188,8 @@ int GetMaxOpenFiles() { void *cacheline_aligned_alloc(size_t size) { #if __GNUC__ < 5 && defined(__SANITIZE_ADDRESS__) return malloc(size); +#elif __cplusplus >= 201703 + return ::operator new(size, std::align_val_t(CACHE_LINE_SIZE)); #elif defined(_ISOC11_SOURCE) return aligned_alloc(CACHE_LINE_SIZE, size); #elif ( _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600 || defined(__APPLE__)) @@ -200,7 +202,13 @@ void *cacheline_aligned_alloc(size_t size) { } void cacheline_aligned_free(void *memblock) { +#if __GNUC__ < 5 && defined(__SANITIZE_ADDRESS__) + free(memblock); +#elif __cplusplus >= 201703 + return ::operator delete(memblock, std::align_val_t(CACHE_LINE_SIZE)); +#else free(memblock); +#endif }