Make base_t's extent_hooks field C11-atomic
This commit is contained in:
parent
56b72c7b17
commit
92aafb0efe
@ -17,11 +17,11 @@ struct base_s {
|
|||||||
/* Associated arena's index within the arenas array. */
|
/* Associated arena's index within the arenas array. */
|
||||||
unsigned ind;
|
unsigned ind;
|
||||||
|
|
||||||
/* User-configurable extent hook functions. */
|
/*
|
||||||
union {
|
* User-configurable extent hook functions. Points to an
|
||||||
extent_hooks_t *extent_hooks;
|
* extent_hooks_t.
|
||||||
void *extent_hooks_pun;
|
*/
|
||||||
};
|
atomic_p_t extent_hooks;
|
||||||
|
|
||||||
/* Protects base_alloc() and base_stats_get() operations. */
|
/* Protects base_alloc() and base_stats_get() operations. */
|
||||||
malloc_mutex_t mtx;
|
malloc_mutex_t mtx;
|
||||||
|
14
src/base.c
14
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,
|
base = (base_t *)base_extent_bump_alloc_helper(&block->extent,
|
||||||
&gap_size, base_size, base_alignment);
|
&gap_size, base_size, base_alignment);
|
||||||
base->ind = ind;
|
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)) {
|
if (malloc_mutex_init(&base->mtx, "base", WITNESS_RANK_BASE)) {
|
||||||
base_unmap(extent_hooks, ind, block, block->size);
|
base_unmap(extent_hooks, ind, block, block->size);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -264,20 +264,14 @@ base_delete(base_t *base) {
|
|||||||
|
|
||||||
extent_hooks_t *
|
extent_hooks_t *
|
||||||
base_extent_hooks_get(base_t *base) {
|
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 *
|
extent_hooks_t *
|
||||||
base_extent_hooks_set(base_t *base, extent_hooks_t *extent_hooks) {
|
base_extent_hooks_set(base_t *base, extent_hooks_t *extent_hooks) {
|
||||||
extent_hooks_t *old_extent_hooks = base_extent_hooks_get(base);
|
extent_hooks_t *old_extent_hooks = base_extent_hooks_get(base);
|
||||||
union {
|
atomic_store_p(&base->extent_hooks, extent_hooks, ATOMIC_RELEASE);
|
||||||
extent_hooks_t **h;
|
|
||||||
void **v;
|
|
||||||
} u;
|
|
||||||
|
|
||||||
u.h = &base->extent_hooks;
|
|
||||||
atomic_write_p(u.v, extent_hooks);
|
|
||||||
|
|
||||||
return old_extent_hooks;
|
return old_extent_hooks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user