aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQi Wang <interwq@gwu.edu>2018-04-11 11:54:11 -0700
committerQi Wang <interwq@gmail.com>2018-04-18 11:20:21 -0700
commitdedfeecc4e69545efb2974ae42589985ed420821 (patch)
tree1619b3e141dc8a146774a485c5fb4bc029bf8a56 /src
parentc95284df1ab77f233562d9bc826523cfaaf7f41e (diff)
downloadplatform_external_jemalloc_new-dedfeecc4e69545efb2974ae42589985ed420821.tar.gz
platform_external_jemalloc_new-dedfeecc4e69545efb2974ae42589985ed420821.tar.bz2
platform_external_jemalloc_new-dedfeecc4e69545efb2974ae42589985ed420821.zip
Invoke dlsym() on demand.
If no lazy lock or background thread is enabled, avoid dlsym pthread_create on boot.
Diffstat (limited to 'src')
-rw-r--r--src/background_thread.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/src/background_thread.c b/src/background_thread.c
index d2aa2745..9656e196 100644
--- a/src/background_thread.c
+++ b/src/background_thread.c
@@ -804,6 +804,26 @@ background_thread_stats_read(tsdn_t *tsdn, background_thread_stats_t *stats) {
#undef BILLION
#undef BACKGROUND_THREAD_MIN_INTERVAL_NS
+static bool
+pthread_create_fptr_init(void) {
+ if (pthread_create_fptr != NULL) {
+ return false;
+ }
+ pthread_create_fptr = dlsym(RTLD_NEXT, "pthread_create");
+ if (pthread_create_fptr == NULL) {
+ can_enable_background_thread = false;
+ if (config_lazy_lock || opt_background_thread) {
+ malloc_write("<jemalloc>: Error in dlsym(RTLD_NEXT, "
+ "\"pthread_create\")\n");
+ abort();
+ }
+ } else {
+ can_enable_background_thread = true;
+ }
+
+ return false;
+}
+
/*
* When lazy lock is enabled, we need to make sure setting isthreaded before
* taking any background_thread locks. This is called early in ctl (instead of
@@ -814,6 +834,7 @@ void
background_thread_ctl_init(tsdn_t *tsdn) {
malloc_mutex_assert_not_owner(tsdn, &background_thread_lock);
#ifdef JEMALLOC_PTHREAD_CREATE_WRAPPER
+ pthread_create_fptr_init();
pthread_create_wrapper_init();
#endif
}
@@ -827,18 +848,10 @@ background_thread_boot0(void) {
"supports pthread only\n");
return true;
}
-
#ifdef JEMALLOC_PTHREAD_CREATE_WRAPPER
- pthread_create_fptr = dlsym(RTLD_NEXT, "pthread_create");
- if (pthread_create_fptr == NULL) {
- can_enable_background_thread = false;
- if (config_lazy_lock || opt_background_thread) {
- malloc_write("<jemalloc>: Error in dlsym(RTLD_NEXT, "
- "\"pthread_create\")\n");
- abort();
- }
- } else {
- can_enable_background_thread = true;
+ if ((config_lazy_lock || opt_background_thread) &&
+ pthread_create_fptr_init()) {
+ return true;
}
#endif
return false;