MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / background_threads_enable

Function background_threads_enable

deps/jemalloc/src/background_thread.c:604–638  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

602}
603
604bool
605background_threads_enable(tsd_t *tsd) {
606 assert(n_background_threads == 0);
607 assert(background_thread_enabled());
608 malloc_mutex_assert_owner(tsd_tsdn(tsd), &background_thread_lock);
609
610 VARIABLE_ARRAY(bool, marked, max_background_threads);
611 unsigned i, nmarked;
612 for (i = 0; i < max_background_threads; i++) {
613 marked[i] = false;
614 }
615 nmarked = 0;
616 /* Thread 0 is required and created at the end. */
617 marked[0] = true;
618 /* Mark the threads we need to create for thread 0. */
619 unsigned n = narenas_total_get();
620 for (i = 1; i < n; i++) {
621 if (marked[i % max_background_threads] ||
622 arena_get(tsd_tsdn(tsd), i, false) == NULL) {
623 continue;
624 }
625 background_thread_info_t *info = &background_thread_info[
626 i % max_background_threads];
627 malloc_mutex_lock(tsd_tsdn(tsd), &info->mtx);
628 assert(info->state == background_thread_stopped);
629 background_thread_init(tsd, info);
630 malloc_mutex_unlock(tsd_tsdn(tsd), &info->mtx);
631 marked[i % max_background_threads] = true;
632 if (++nmarked == max_background_threads) {
633 break;
634 }
635 }
636
637 return background_thread_create_locked(tsd, 0);
638}
639
640bool
641background_threads_disable(tsd_t *tsd) {

Callers 3

ctl.cFile · 0.70

Calls 9

narenas_total_getFunction · 0.70
background_thread_initFunction · 0.70
tsd_tsdnFunction · 0.50
arena_getFunction · 0.50
malloc_mutex_lockFunction · 0.50
malloc_mutex_unlockFunction · 0.50

Tested by

no test coverage detected