]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commitdiff
port_posix: use new(size, std::align_val_t) for aligned_alloc
authorKefu Chai <tchaikov@gmail.com>
Wed, 25 Apr 2018 02:31:51 +0000 (10:31 +0800)
committerKefu Chai <tchaikov@gmail.com>
Wed, 25 Apr 2018 02:34:27 +0000 (10:34 +0800)
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 <tchaikov@gmail.com>
CMakeLists.txt
port/port_posix.cc

index 18f896944d9bebe7797ed463687377677c880eff..c55e091ddfbc0321e00a50536ce2c585ff025762 100644 (file)
@@ -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)
index 2408beeb030bfa4d239453bbe3dd4cdec582864f..6e9ea64507d4833f1530169112993a924017b4bd 100644 (file)
@@ -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
 }