From 27c44a15f0b8de0235de0939cf4fb2f2b8aa215c Mon Sep 17 00:00:00 2001 From: Kamil Rytarowski Date: Wed, 3 Jun 2020 13:29:30 +0200 Subject: [PATCH 1/2] Use JEMALLOC_MALLOC_THREAD_CLEANUP --- external/bsd/jemalloc/dist/src/tsd.c | 4 ++++ .../include/jemalloc/internal/jemalloc_internal_defs.h | 2 +- lib/libpthread/pthread.c | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/external/bsd/jemalloc/dist/src/tsd.c b/external/bsd/jemalloc/dist/src/tsd.c index 8edf966e4c09..2d257169f6f0 100644 --- a/external/bsd/jemalloc/dist/src/tsd.c +++ b/external/bsd/jemalloc/dist/src/tsd.c @@ -169,6 +169,10 @@ malloc_tsd_dalloc(void *wrapper) { a0dalloc(wrapper); } +__BEGIN_DECLS +void _malloc_thread_cleanup(void); +__END_DECLS + #if defined(JEMALLOC_MALLOC_THREAD_CLEANUP) || defined(_WIN32) #ifndef _WIN32 JEMALLOC_EXPORT diff --git a/external/bsd/jemalloc/include/jemalloc/internal/jemalloc_internal_defs.h b/external/bsd/jemalloc/include/jemalloc/internal/jemalloc_internal_defs.h index 5a7a82037ab7..88bbf8133209 100644 --- a/external/bsd/jemalloc/include/jemalloc/internal/jemalloc_internal_defs.h +++ b/external/bsd/jemalloc/include/jemalloc/internal/jemalloc_internal_defs.h @@ -138,7 +138,7 @@ * _malloc_thread_cleanup() exists, use it as the basis for thread cleanup in * malloc_tsd. */ -/* #undef JEMALLOC_MALLOC_THREAD_CLEANUP */ +#define JEMALLOC_MALLOC_THREAD_CLEANUP /* * Defined if threaded initialization is known to be safe on this platform. diff --git a/lib/libpthread/pthread.c b/lib/libpthread/pthread.c index 343b52cbd9ca..7a42b014e46c 100644 --- a/lib/libpthread/pthread.c +++ b/lib/libpthread/pthread.c @@ -66,6 +66,10 @@ __RCSID("$NetBSD: pthread.c,v 1.167 2020/02/16 17:45:11 kamil Exp $"); #include "pthread_makelwp.h" #include "reentrant.h" +__BEGIN_DECLS +void _malloc_thread_cleanup(void) __weak; +__END_DECLS + pthread_rwlock_t pthread__alltree_lock = PTHREAD_RWLOCK_INITIALIZER; static rb_tree_t pthread__alltree; @@ -678,6 +682,9 @@ pthread_exit(void *retval) /* Perform cleanup of thread-specific data */ pthread__destroy_tsd(self); + if (_malloc_thread_cleanup) + _malloc_thread_cleanup(); + /* * Signal our exit. Our stack and pthread_t won't be reused until * pthread_create() can see from kernel info that this LWP is gone. -- 2.25.2