1 #ifndef JEMALLOC_INTERNAL_BACKGROUND_THREAD_INLINES_H
2 #define JEMALLOC_INTERNAL_BACKGROUND_THREAD_INLINES_H
4 JEMALLOC_ALWAYS_INLINE bool
5 background_thread_enabled(void) {
6 return atomic_load_b(&background_thread_enabled_state, ATOMIC_RELAXED);
9 JEMALLOC_ALWAYS_INLINE void
10 background_thread_enabled_set(tsdn_t *tsdn, bool state) {
11 malloc_mutex_assert_owner(tsdn, &background_thread_lock);
12 atomic_store_b(&background_thread_enabled_state, state, ATOMIC_RELAXED);
15 JEMALLOC_ALWAYS_INLINE background_thread_info_t *
16 arena_background_thread_info_get(arena_t *arena) {
17 unsigned arena_ind = arena_ind_get(arena);
18 return &background_thread_info[arena_ind % ncpus];
21 JEMALLOC_ALWAYS_INLINE uint64_t
22 background_thread_wakeup_time_get(background_thread_info_t *info) {
23 uint64_t next_wakeup = nstime_ns(&info->next_wakeup);
24 assert(atomic_load_b(&info->indefinite_sleep, ATOMIC_ACQUIRE) ==
25 (next_wakeup == BACKGROUND_THREAD_INDEFINITE_SLEEP));
29 JEMALLOC_ALWAYS_INLINE void
30 background_thread_wakeup_time_set(tsdn_t *tsdn, background_thread_info_t *info,
31 uint64_t wakeup_time) {
32 malloc_mutex_assert_owner(tsdn, &info->mtx);
33 atomic_store_b(&info->indefinite_sleep,
34 wakeup_time == BACKGROUND_THREAD_INDEFINITE_SLEEP, ATOMIC_RELEASE);
35 nstime_init(&info->next_wakeup, wakeup_time);
38 JEMALLOC_ALWAYS_INLINE bool
39 background_thread_indefinite_sleep(background_thread_info_t *info) {
40 return atomic_load_b(&info->indefinite_sleep, ATOMIC_ACQUIRE);
43 JEMALLOC_ALWAYS_INLINE void
44 arena_background_thread_inactivity_check(tsdn_t *tsdn, arena_t *arena,
45 bool is_background_thread) {
46 if (!background_thread_enabled() || is_background_thread) {
49 background_thread_info_t *info =
50 arena_background_thread_info_get(arena);
51 if (background_thread_indefinite_sleep(info)) {
52 background_thread_interval_check(tsdn, arena,
53 &arena->decay_dirty, 0);
57 #endif /* JEMALLOC_INTERNAL_BACKGROUND_THREAD_INLINES_H */