From 43f0ce92d881f945da54a498cadc654ddb9403a1 Mon Sep 17 00:00:00 2001 From: Yinan Zhang Date: Fri, 1 Nov 2019 14:11:59 -0700 Subject: [PATCH] Define general purpose tsd_thread_event_init() --- include/jemalloc/internal/thread_event.h | 1 + src/thread_event.c | 29 ++++++++++++++++++++++++ src/tsd.c | 4 +--- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/include/jemalloc/internal/thread_event.h b/include/jemalloc/internal/thread_event.h index 3da9f0a6..8a05eaed 100644 --- a/include/jemalloc/internal/thread_event.h +++ b/include/jemalloc/internal/thread_event.h @@ -27,6 +27,7 @@ void thread_event_trigger(tsd_t *tsd, bool delay_event); void thread_event_rollback(tsd_t *tsd, size_t diff); void thread_event_update(tsd_t *tsd); void thread_event_boot(); +void tsd_thread_event_init(tsd_t *tsd); /* * List of all events, in the following format: diff --git a/src/thread_event.c b/src/thread_event.c index 33d669aa..f27a37aa 100644 --- a/src/thread_event.c +++ b/src/thread_event.c @@ -11,6 +11,13 @@ */ static bool thread_event_active = false; +/* TSD event init function signatures. */ +#define E(event, condition) \ +static void tsd_thread_##event##_event_init(tsd_t *tsd); + +ITERATE_OVER_ALL_EVENTS +#undef E + /* Event handler function signatures. */ #define E(event, condition) \ static void thread_##event##_event_handler(tsd_t *tsd); @@ -18,6 +25,18 @@ static void thread_##event##_event_handler(tsd_t *tsd); ITERATE_OVER_ALL_EVENTS #undef E +static void +tsd_thread_tcache_gc_event_init(tsd_t *tsd) { + assert(TCACHE_GC_INCR_BYTES > 0); + thread_tcache_gc_event_update(tsd, TCACHE_GC_INCR_BYTES); +} + +static void +tsd_thread_prof_sample_event_init(tsd_t *tsd) { + assert(config_prof && opt_prof); + /* Do not set sample interval until the first allocation. */ +} + static void thread_tcache_gc_event_handler(tsd_t *tsd) { assert(TCACHE_GC_INCR_BYTES > 0); @@ -270,3 +289,13 @@ void thread_event_boot() { ITERATE_OVER_ALL_EVENTS #undef E } + +void tsd_thread_event_init(tsd_t *tsd) { +#define E(event, condition) \ + if (condition) { \ + tsd_thread_##event##_event_init(tsd); \ + } + + ITERATE_OVER_ALL_EVENTS +#undef E +} diff --git a/src/tsd.c b/src/tsd.c index 3fa43d30..bb40af14 100644 --- a/src/tsd.c +++ b/src/tsd.c @@ -233,9 +233,7 @@ tsd_data_init(tsd_t *tsd) { *tsd_offset_statep_get(tsd) = config_debug ? 0 : (uint64_t)(uintptr_t)tsd; - if (TCACHE_GC_INCR_BYTES > 0) { - thread_tcache_gc_event_update(tsd, TCACHE_GC_INCR_BYTES); - } + tsd_thread_event_init(tsd); return tsd_tcache_enabled_data_init(tsd); }