mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-06-04 19:24:17 +03:00
edata_cache: Remember the associated base_t.
This will save us some trouble down the line when we stop passing arena pointers everywhere; we won't have to pass around a base_t pointer either.
This commit is contained in:
parent
ae23e5f426
commit
c792f3e4ab
5 changed files with 20 additions and 16 deletions
|
|
@ -2,23 +2,29 @@
|
|||
#include "jemalloc/internal/jemalloc_internal_includes.h"
|
||||
|
||||
bool
|
||||
edata_cache_init(edata_cache_t *edata_cache) {
|
||||
edata_cache_init(edata_cache_t *edata_cache, base_t *base) {
|
||||
edata_avail_new(&edata_cache->avail);
|
||||
/*
|
||||
* This is not strictly necessary, since the edata_cache_t is only
|
||||
* created inside an arena, which is zeroed on creation. But this is
|
||||
* handy as a safety measure.
|
||||
*/
|
||||
atomic_store_zu(&edata_cache->count, 0, ATOMIC_RELAXED);
|
||||
if (malloc_mutex_init(&edata_cache->mtx, "edata_cache",
|
||||
WITNESS_RANK_EDATA_CACHE, malloc_mutex_rank_exclusive)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
edata_avail_new(&edata_cache->avail);
|
||||
edata_cache->base = base;
|
||||
return false;
|
||||
}
|
||||
|
||||
edata_t *
|
||||
edata_cache_get(tsdn_t *tsdn, edata_cache_t *edata_cache, base_t *base) {
|
||||
edata_cache_get(tsdn_t *tsdn, edata_cache_t *edata_cache) {
|
||||
malloc_mutex_lock(tsdn, &edata_cache->mtx);
|
||||
edata_t *edata = edata_avail_first(&edata_cache->avail);
|
||||
if (edata == NULL) {
|
||||
malloc_mutex_unlock(tsdn, &edata_cache->mtx);
|
||||
return base_alloc_edata(tsdn, base);
|
||||
return base_alloc_edata(tsdn, edata_cache->base);
|
||||
}
|
||||
edata_avail_remove(&edata_cache->avail, edata);
|
||||
atomic_fetch_sub_zu(&edata_cache->count, 1, ATOMIC_RELAXED);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue