summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Goldblatt <davidgoldblatt@fb.com>2017-04-05 00:32:21 (GMT)
committerDavid Goldblatt <davidtgoldblatt@gmail.com>2017-04-05 23:25:37 (GMT)
commit92aafb0efe47dbca23fb5b54c33fd4504601ae76 (patch)
treeaf6184752c1e6144284028366fd15888f12b8609
parent56b72c7b1781ef75c2450a08e08079fe164bb2df (diff)
downloadjemalloc-92aafb0efe47dbca23fb5b54c33fd4504601ae76.zip
jemalloc-92aafb0efe47dbca23fb5b54c33fd4504601ae76.tar.gz
jemalloc-92aafb0efe47dbca23fb5b54c33fd4504601ae76.tar.bz2
Make base_t's extent_hooks field C11-atomic
-rw-r--r--include/jemalloc/internal/base_structs.h10
-rw-r--r--src/base.c14
2 files changed, 9 insertions, 15 deletions
diff --git a/include/jemalloc/internal/base_structs.h b/include/jemalloc/internal/base_structs.h
index bad37c0..13d5bd4 100644
--- a/include/jemalloc/internal/base_structs.h
+++ b/include/jemalloc/internal/base_structs.h
@@ -17,11 +17,11 @@ struct base_s {
/* Associated arena's index within the arenas array. */
unsigned ind;
- /* User-configurable extent hook functions. */
- union {
- extent_hooks_t *extent_hooks;
- void *extent_hooks_pun;
- };
+ /*
+ * User-configurable extent hook functions. Points to an
+ * extent_hooks_t.
+ */
+ atomic_p_t extent_hooks;
/* Protects base_alloc() and base_stats_get() operations. */
malloc_mutex_t mtx;
diff --git a/src/base.c b/src/base.c
index b1a4ae3..4275259 100644
--- a/src/base.c
+++ b/src/base.c
@@ -227,7 +227,7 @@ base_new(tsdn_t *tsdn, unsigned ind, extent_hooks_t *extent_hooks) {
base = (base_t *)base_extent_bump_alloc_helper(&block->extent,
&gap_size, base_size, base_alignment);
base->ind = ind;
- base->extent_hooks = extent_hooks;
+ atomic_store_p(&base->extent_hooks, extent_hooks, ATOMIC_RELAXED);
if (malloc_mutex_init(&base->mtx, "base", WITNESS_RANK_BASE)) {
base_unmap(extent_hooks, ind, block, block->size);
return NULL;
@@ -264,20 +264,14 @@ base_delete(base_t *base) {
extent_hooks_t *
base_extent_hooks_get(base_t *base) {
- return (extent_hooks_t *)atomic_read_p(&base->extent_hooks_pun);
+ return (extent_hooks_t *)atomic_load_p(&base->extent_hooks,
+ ATOMIC_ACQUIRE);
}
extent_hooks_t *
base_extent_hooks_set(base_t *base, extent_hooks_t *extent_hooks) {
extent_hooks_t *old_extent_hooks = base_extent_hooks_get(base);
- union {
- extent_hooks_t **h;
- void **v;
- } u;
-
- u.h = &base->extent_hooks;
- atomic_write_p(u.v, extent_hooks);
-
+ atomic_store_p(&base->extent_hooks, extent_hooks, ATOMIC_RELEASE);
return old_extent_hooks;
}