diff options
author | jasone <jasone@FreeBSD.org> | 2012-04-17 07:22:14 +0000 |
---|---|---|
committer | jasone <jasone@FreeBSD.org> | 2012-04-17 07:22:14 +0000 |
commit | cbeacb7c46f3a3650e5dbefa9a1a18bc9943a8cc (patch) | |
tree | 24efdb5b31d087479e78f72f3b772bd5b02e470c /contrib/jemalloc/src/tsd.c | |
parent | 1bc364bf7eebf6139e4f968987974484d35c5cb4 (diff) | |
download | FreeBSD-src-cbeacb7c46f3a3650e5dbefa9a1a18bc9943a8cc.zip FreeBSD-src-cbeacb7c46f3a3650e5dbefa9a1a18bc9943a8cc.tar.gz |
Import jemalloc 9ef7f5dc34ff02f50d401e41c8d9a4a928e7c2aa (dev branch,
prior to 3.0.0 release) as contrib/jemalloc, and integrate it into libc.
The code being imported by this commit diverged from
lib/libc/stdlib/malloc.c in March 2010, which means that a portion of
the jemalloc 1.0.0 ChangeLog entries are relevant, as are the entries
for all subsequent releases.
Diffstat (limited to 'contrib/jemalloc/src/tsd.c')
-rw-r--r-- | contrib/jemalloc/src/tsd.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/contrib/jemalloc/src/tsd.c b/contrib/jemalloc/src/tsd.c new file mode 100644 index 0000000..0838dc8 --- /dev/null +++ b/contrib/jemalloc/src/tsd.c @@ -0,0 +1,72 @@ +#define JEMALLOC_TSD_C_ +#include "jemalloc/internal/jemalloc_internal.h" + +/******************************************************************************/ +/* Data. */ + +static unsigned ncleanups; +static malloc_tsd_cleanup_t cleanups[MALLOC_TSD_CLEANUPS_MAX]; + +/******************************************************************************/ + +void * +malloc_tsd_malloc(size_t size) +{ + + /* Avoid choose_arena() in order to dodge bootstrapping issues. */ + return arena_malloc(arenas[0], size, false, false); +} + +void +malloc_tsd_dalloc(void *wrapper) +{ + + idalloc(wrapper); +} + +void +malloc_tsd_no_cleanup(void *arg) +{ + + not_reached(); +} + +#ifdef JEMALLOC_MALLOC_THREAD_CLEANUP +void +_malloc_thread_cleanup(void) +{ + bool pending[ncleanups], again; + unsigned i; + + for (i = 0; i < ncleanups; i++) + pending[i] = true; + + do { + again = false; + for (i = 0; i < ncleanups; i++) { + if (pending[i]) { + pending[i] = cleanups[i].f(cleanups[i].arg); + if (pending[i]) + again = true; + } + } + } while (again); +} +#endif + +void +malloc_tsd_cleanup_register(bool (*f)(void *), void *arg) +{ + + assert(ncleanups < MALLOC_TSD_CLEANUPS_MAX); + cleanups[ncleanups].f = f; + cleanups[ncleanups].arg = arg; + ncleanups++; +} + +void +malloc_tsd_boot(void) +{ + + ncleanups = 0; +} |