From dc25405d6d818fd0106bea3b5106ad0aafa543cb Mon Sep 17 00:00:00 2001 From: Eduardo Souza Date: Mon, 2 Sep 2024 01:27:08 +0000 Subject: [PATCH] Moving gc_enable code to gc-common.c --- src/gc-common.c | 30 ++++++++++++++++++++++++++++++ src/gc-stock.c | 30 ------------------------------ 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/gc-common.c b/src/gc-common.c index 2ec167caa667a3..03c046bc300f29 100644 --- a/src/gc-common.c +++ b/src/gc-common.c @@ -613,6 +613,36 @@ void jl_gc_track_malloced_genericmemory(jl_ptls_t ptls, jl_genericmemory_t *m, i ptls->gc_tls.heap.mallocarrays = ma; } +// collector entry point and control +_Atomic(uint32_t) jl_gc_disable_counter = 1; + +JL_DLLEXPORT int jl_gc_enable(int on) +{ + jl_ptls_t ptls = jl_current_task->ptls; + int prev = !ptls->disable_gc; + ptls->disable_gc = (on == 0); + if (on && !prev) { + // disable -> enable + if (jl_atomic_fetch_add(&jl_gc_disable_counter, -1) == 1) { + gc_num.allocd += gc_num.deferred_alloc; + gc_num.deferred_alloc = 0; + } + } + else if (prev && !on) { + // enable -> disable + jl_atomic_fetch_add(&jl_gc_disable_counter, 1); + // check if the GC is running and wait for it to finish + jl_gc_safepoint_(ptls); + } + return prev; +} + +JL_DLLEXPORT int jl_gc_is_enabled(void) +{ + jl_ptls_t ptls = jl_current_task->ptls; + return !ptls->disable_gc; +} + int gc_logging_enabled = 0; JL_DLLEXPORT void jl_enable_gc_logging(int enable) { diff --git a/src/gc-stock.c b/src/gc-stock.c index 9b633cacd7870b..61fc8d4e83a3ab 100644 --- a/src/gc-stock.c +++ b/src/gc-stock.c @@ -2801,36 +2801,6 @@ int gc_is_concurrent_collector_thread(int tid) JL_NOTSAFEPOINT return tid == concurrent_collector_thread_id; } -// collector entry point and control -_Atomic(uint32_t) jl_gc_disable_counter = 1; - -JL_DLLEXPORT int jl_gc_enable(int on) -{ - jl_ptls_t ptls = jl_current_task->ptls; - int prev = !ptls->disable_gc; - ptls->disable_gc = (on == 0); - if (on && !prev) { - // disable -> enable - if (jl_atomic_fetch_add(&jl_gc_disable_counter, -1) == 1) { - gc_num.allocd += gc_num.deferred_alloc; - gc_num.deferred_alloc = 0; - } - } - else if (prev && !on) { - // enable -> disable - jl_atomic_fetch_add(&jl_gc_disable_counter, 1); - // check if the GC is running and wait for it to finish - jl_gc_safepoint_(ptls); - } - return prev; -} - -JL_DLLEXPORT int jl_gc_is_enabled(void) -{ - jl_ptls_t ptls = jl_current_task->ptls; - return !ptls->disable_gc; -} - JL_DLLEXPORT void jl_gc_get_total_bytes(int64_t *bytes) JL_NOTSAFEPOINT { jl_gc_num_t num = gc_num;