aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorDave Watson <davejwatson@fb.com>2016-10-23 15:56:30 -0700
committerJason Evans <jasone@canonware.com>2016-12-12 18:36:06 -0800
commit2319152d9f5d9b33eebc36a50ccf4239f31c1ad9 (patch)
tree44a848c13219a110dec96d2969f6135f2a3c54f7 /include
parentd4c5aceb7cb5c5cf7a6dfd62e072c7dd12188998 (diff)
downloadplatform_external_jemalloc_new-2319152d9f5d9b33eebc36a50ccf4239f31c1ad9.tar.gz
platform_external_jemalloc_new-2319152d9f5d9b33eebc36a50ccf4239f31c1ad9.tar.bz2
platform_external_jemalloc_new-2319152d9f5d9b33eebc36a50ccf4239f31c1ad9.zip
jemalloc cpp new/delete bindings
Adds cpp bindings for jemalloc, along with necessary autoconf settings. This is mostly to add sized deallocation support, which can't be added from C directly. Sized deallocation is ~10% microbench improvement. * Import ax_cxx_compile_stdcxx.m4 from the autoconf repo, seems like the easiest way to get c++14 detection. * Adds various other changes, like CXXFLAGS, to configure.ac. * Adds new rules to Makefile.in for src/jemalloc-cpp.cpp, and a basic unittest. * Both new and delete are overridden, to ensure jemalloc is used for both. * TODO future enhancement of avoiding extra PLT thunks for new and delete - sdallocx and malloc are publicly exported jemalloc symbols, using an alias would link them directly. Unfortunately, was having trouble getting it to play nice with jemalloc's namespace support. Testing: Tested gcc 4.8, gcc 5, gcc 5.2, clang 4.0. Only gcc >= 5 has sized deallocation support, verified that the rest build correctly. Tested mac osx and Centos. Tested --with-jemalloc-prefix and --without-export. This resolves #202.
Diffstat (limited to 'include')
-rw-r--r--include/jemalloc/internal/jemalloc_internal.h.in13
-rw-r--r--include/jemalloc/internal/jemalloc_internal_macros.h2
-rw-r--r--include/jemalloc/internal/rtree.h8
3 files changed, 17 insertions, 6 deletions
diff --git a/include/jemalloc/internal/jemalloc_internal.h.in b/include/jemalloc/internal/jemalloc_internal.h.in
index 85b34012..ba5207d8 100644
--- a/include/jemalloc/internal/jemalloc_internal.h.in
+++ b/include/jemalloc/internal/jemalloc_internal.h.in
@@ -1,6 +1,10 @@
#ifndef JEMALLOC_INTERNAL_H
#define JEMALLOC_INTERNAL_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include "jemalloc_internal_defs.h"
#include "jemalloc/internal/jemalloc_internal_decls.h"
@@ -135,7 +139,7 @@ static const bool config_cache_oblivious =
#endif
;
-#ifdef JEMALLOC_C11ATOMICS
+#if defined(JEMALLOC_C11ATOMICS) && !defined(__cplusplus)
#include <stdatomic.h>
#endif
@@ -888,7 +892,7 @@ arena_get(tsdn_t *tsdn, unsigned ind, bool init_if_missing)
ret = arenas[ind];
if (unlikely(ret == NULL)) {
- ret = atomic_read_p((void *)&arenas[ind]);
+ ret = (arena_t *)atomic_read_p((void **)&arenas[ind]);
if (init_if_missing && unlikely(ret == NULL))
ret = arena_init(tsdn, ind);
}
@@ -1194,4 +1198,9 @@ ixalloc(tsdn_t *tsdn, extent_t *extent, void *ptr, size_t oldsize, size_t size,
#undef JEMALLOC_H_INLINES
/******************************************************************************/
+
+#ifdef __cplusplus
+}
+#endif
+
#endif /* JEMALLOC_INTERNAL_H */
diff --git a/include/jemalloc/internal/jemalloc_internal_macros.h b/include/jemalloc/internal/jemalloc_internal_macros.h
index a08ba772..57492049 100644
--- a/include/jemalloc/internal/jemalloc_internal_macros.h
+++ b/include/jemalloc/internal/jemalloc_internal_macros.h
@@ -52,6 +52,6 @@
# define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var))
#endif
-#ifndef JEMALLOC_HAS_RESTRICT
+#if !defined(JEMALLOC_HAS_RESTRICT) || defined(__cplusplus)
# define restrict
#endif
diff --git a/include/jemalloc/internal/rtree.h b/include/jemalloc/internal/rtree.h
index 9c6cc22f..b2a2800e 100644
--- a/include/jemalloc/internal/rtree.h
+++ b/include/jemalloc/internal/rtree.h
@@ -260,7 +260,7 @@ rtree_child_tryread(rtree_elm_t *elm, bool dependent)
/* Double-checked read (first read may be stale). */
child = elm->child;
if (!dependent && !rtree_node_valid(child))
- child = atomic_read_p(&elm->pun);
+ child = (rtree_elm_t *)atomic_read_p(&elm->pun);
assert(!dependent || child != NULL);
return (child);
}
@@ -320,8 +320,10 @@ rtree_subtree_tryread(rtree_t *rtree, unsigned level, bool dependent)
/* Double-checked read (first read may be stale). */
subtree = rtree->levels[level].subtree;
- if (!dependent && unlikely(!rtree_node_valid(subtree)))
- subtree = atomic_read_p(&rtree->levels[level].subtree_pun);
+ if (!dependent && unlikely(!rtree_node_valid(subtree))) {
+ subtree = (rtree_elm_t *)atomic_read_p(
+ &rtree->levels[level].subtree_pun);
+ }
assert(!dependent || subtree != NULL);
return (subtree);
}