mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-22 08:37:18 +03:00
Pull out edata_t caching into its own module.
This commit is contained in:
parent
a7862df616
commit
7859184179
12 changed files with 106 additions and 60 deletions
47
src/edata_cache.c
Normal file
47
src/edata_cache.c
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
#include "jemalloc/internal/jemalloc_preamble.h"
|
||||
#include "jemalloc/internal/jemalloc_internal_includes.h"
|
||||
|
||||
bool
|
||||
edata_cache_init(edata_cache_t *edata_cache) {
|
||||
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);
|
||||
return false;
|
||||
}
|
||||
|
||||
edata_t *
|
||||
edata_cache_get(tsdn_t *tsdn, edata_cache_t *edata_cache, base_t *base) {
|
||||
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);
|
||||
}
|
||||
edata_avail_remove(&edata_cache->avail, edata);
|
||||
atomic_fetch_sub_zu(&edata_cache->count, 1, ATOMIC_RELAXED);
|
||||
malloc_mutex_unlock(tsdn, &edata_cache->mtx);
|
||||
return edata;
|
||||
}
|
||||
|
||||
void
|
||||
edata_cache_put(tsdn_t *tsdn, edata_cache_t *edata_cache, edata_t *edata) {
|
||||
malloc_mutex_lock(tsdn, &edata_cache->mtx);
|
||||
edata_avail_insert(&edata_cache->avail, edata);
|
||||
atomic_fetch_add_zu(&edata_cache->count, 1, ATOMIC_RELAXED);
|
||||
malloc_mutex_unlock(tsdn, &edata_cache->mtx);
|
||||
}
|
||||
|
||||
void edata_cache_prefork(tsdn_t *tsdn, edata_cache_t *edata_cache) {
|
||||
malloc_mutex_prefork(tsdn, &edata_cache->mtx);
|
||||
}
|
||||
|
||||
void edata_cache_postfork_parent(tsdn_t *tsdn, edata_cache_t *edata_cache) {
|
||||
malloc_mutex_postfork_parent(tsdn, &edata_cache->mtx);
|
||||
}
|
||||
|
||||
void edata_cache_postfork_child(tsdn_t *tsdn, edata_cache_t *edata_cache) {
|
||||
malloc_mutex_postfork_child(tsdn, &edata_cache->mtx);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue