Fix the lock owner sanity checking during background thread boot.

During boot, some mutexes are not initialized yet, plus there's no point taking
many mutexes while everything is covered by the global init lock, so the locking
assumptions in some functions (e.g. background_thread_enabled_set()) can't be
enforced.  Skip the lock owner check in this case.
This commit is contained in:
Qi Wang 2024-09-20 20:24:30 -07:00 committed by Qi Wang
parent 0181aaa495
commit 44db479fad
2 changed files with 8 additions and 3 deletions

View File

@ -11,10 +11,15 @@ background_thread_enabled(void) {
return atomic_load_b(&background_thread_enabled_state, ATOMIC_RELAXED);
}
JEMALLOC_ALWAYS_INLINE void
background_thread_enabled_set_impl(bool state) {
atomic_store_b(&background_thread_enabled_state, state, ATOMIC_RELAXED);
}
JEMALLOC_ALWAYS_INLINE void
background_thread_enabled_set(tsdn_t *tsdn, bool state) {
malloc_mutex_assert_owner(tsdn, &background_thread_lock);
atomic_store_b(&background_thread_enabled_state, state, ATOMIC_RELAXED);
background_thread_enabled_set_impl(state);
}
JEMALLOC_ALWAYS_INLINE background_thread_info_t *

View File

@ -819,7 +819,6 @@ background_thread_boot1(tsdn_t *tsdn, base_t *base) {
}
max_background_threads = opt_max_background_threads;
background_thread_enabled_set(tsdn, opt_background_thread);
if (malloc_mutex_init(&background_thread_lock,
"background_thread_global",
WITNESS_RANK_BACKGROUND_THREAD_GLOBAL,
@ -850,7 +849,8 @@ background_thread_boot1(tsdn_t *tsdn, base_t *base) {
background_thread_info_init(tsdn, info);
malloc_mutex_unlock(tsdn, &info->mtx);
}
/* Using _impl to bypass the locking check during init. */
background_thread_enabled_set_impl(opt_background_thread);
#endif
return false;
}