| 892 | } |
| 893 | |
| 894 | bool |
| 895 | background_thread_boot1(tsdn_t *tsdn) { |
| 896 | #ifdef JEMALLOC_BACKGROUND_THREAD |
| 897 | assert(have_background_thread); |
| 898 | assert(narenas_total_get() > 0); |
| 899 | |
| 900 | if (opt_max_background_threads > MAX_BACKGROUND_THREAD_LIMIT) { |
| 901 | opt_max_background_threads = DEFAULT_NUM_BACKGROUND_THREAD; |
| 902 | } |
| 903 | max_background_threads = opt_max_background_threads; |
| 904 | |
| 905 | background_thread_enabled_set(tsdn, opt_background_thread); |
| 906 | if (malloc_mutex_init(&background_thread_lock, |
| 907 | "background_thread_global", |
| 908 | WITNESS_RANK_BACKGROUND_THREAD_GLOBAL, |
| 909 | malloc_mutex_rank_exclusive)) { |
| 910 | return true; |
| 911 | } |
| 912 | |
| 913 | background_thread_info = (background_thread_info_t *)base_alloc(tsdn, |
| 914 | b0get(), opt_max_background_threads * |
| 915 | sizeof(background_thread_info_t), CACHELINE); |
| 916 | if (background_thread_info == NULL) { |
| 917 | return true; |
| 918 | } |
| 919 | |
| 920 | for (unsigned i = 0; i < max_background_threads; i++) { |
| 921 | background_thread_info_t *info = &background_thread_info[i]; |
| 922 | /* Thread mutex is rank_inclusive because of thread0. */ |
| 923 | if (malloc_mutex_init(&info->mtx, "background_thread", |
| 924 | WITNESS_RANK_BACKGROUND_THREAD, |
| 925 | malloc_mutex_address_ordered)) { |
| 926 | return true; |
| 927 | } |
| 928 | if (pthread_cond_init(&info->cond, NULL)) { |
| 929 | return true; |
| 930 | } |
| 931 | malloc_mutex_lock(tsdn, &info->mtx); |
| 932 | info->state = background_thread_stopped; |
| 933 | background_thread_info_init(tsdn, info); |
| 934 | malloc_mutex_unlock(tsdn, &info->mtx); |
| 935 | } |
| 936 | #endif |
| 937 | |
| 938 | return false; |
| 939 | } |
no test coverage detected