]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/rocksdb/port/jemalloc_helper.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / rocksdb / port / jemalloc_helper.h
index 0c216face13e7a8f959e4b23baac67b6410fbb91..f6f72f8cb8c3458bbdc7bdafb0b236f7fbd302aa 100644 (file)
@@ -5,10 +5,24 @@
 
 #pragma once
 
+#if defined(__clang__)
+// glibc's `posix_memalign()` declaration specifies `throw()` while clang's
+// declaration does not. There is a hack in clang to make its re-declaration
+// compatible with glibc's if they are declared consecutively. That hack breaks
+// if yet another `posix_memalign()` declaration comes between glibc's and
+// clang's declarations. Include "mm_malloc.h" here ensures glibc's and clang's
+// declarations both come before "jemalloc.h"'s `posix_memalign()` declaration.
+//
+// This problem could also be avoided if "jemalloc.h"'s `posix_memalign()`
+// declaration did not specify `throw()` when built with clang.
+#include <mm_malloc.h>
+#endif
+
 #ifdef ROCKSDB_JEMALLOC
 #ifdef __FreeBSD__
 #include <malloc_np.h>
 #else
+#define JEMALLOC_MANGLE
 #include <jemalloc/jemalloc.h>
 #endif
 
 #define JEMALLOC_CXX_THROW
 #endif
 
+#if defined(OS_WIN) && defined(_MSC_VER)
+
+// MSVC does not have weak symbol support. As long as ROCKSDB_JEMALLOC is
+// defined, Jemalloc memory allocator is used.
+static inline bool HasJemalloc() { return true; }
+
+#else
+
 // Declare non-standard jemalloc APIs as weak symbols. We can null-check these
 // symbols to detect whether jemalloc is linked with the binary.
 extern "C" void* mallocx(size_t, int) __attribute__((__weak__));
@@ -50,4 +72,6 @@ static inline bool HasJemalloc() {
          malloc_stats_print != nullptr && malloc_usable_size != nullptr;
 }
 
+#endif
+
 #endif  // ROCKSDB_JEMALLOC