Skip to content

Commit 331ffea

Browse files
committed
Moving gc_enable code to gc-common.c
1 parent 058d676 commit 331ffea

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

src/gc-common.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,36 @@ void jl_gc_track_malloced_genericmemory(jl_ptls_t ptls, jl_genericmemory_t *m, i
613613
ptls->gc_tls.heap.mallocarrays = ma;
614614
}
615615

616+
// collector entry point and control
617+
_Atomic(uint32_t) jl_gc_disable_counter = 1;
618+
619+
JL_DLLEXPORT int jl_gc_enable(int on)
620+
{
621+
jl_ptls_t ptls = jl_current_task->ptls;
622+
int prev = !ptls->disable_gc;
623+
ptls->disable_gc = (on == 0);
624+
if (on && !prev) {
625+
// disable -> enable
626+
if (jl_atomic_fetch_add(&jl_gc_disable_counter, -1) == 1) {
627+
gc_num.allocd += gc_num.deferred_alloc;
628+
gc_num.deferred_alloc = 0;
629+
}
630+
}
631+
else if (prev && !on) {
632+
// enable -> disable
633+
jl_atomic_fetch_add(&jl_gc_disable_counter, 1);
634+
// check if the GC is running and wait for it to finish
635+
jl_gc_safepoint_(ptls);
636+
}
637+
return prev;
638+
}
639+
640+
JL_DLLEXPORT int jl_gc_is_enabled(void)
641+
{
642+
jl_ptls_t ptls = jl_current_task->ptls;
643+
return !ptls->disable_gc;
644+
}
645+
616646
int gc_logging_enabled = 0;
617647

618648
JL_DLLEXPORT void jl_enable_gc_logging(int enable) {

src/gc-stock.c

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,36 +2801,6 @@ int gc_is_concurrent_collector_thread(int tid) JL_NOTSAFEPOINT
28012801
return tid == concurrent_collector_thread_id;
28022802
}
28032803

2804-
// collector entry point and control
2805-
_Atomic(uint32_t) jl_gc_disable_counter = 1;
2806-
2807-
JL_DLLEXPORT int jl_gc_enable(int on)
2808-
{
2809-
jl_ptls_t ptls = jl_current_task->ptls;
2810-
int prev = !ptls->disable_gc;
2811-
ptls->disable_gc = (on == 0);
2812-
if (on && !prev) {
2813-
// disable -> enable
2814-
if (jl_atomic_fetch_add(&jl_gc_disable_counter, -1) == 1) {
2815-
gc_num.allocd += gc_num.deferred_alloc;
2816-
gc_num.deferred_alloc = 0;
2817-
}
2818-
}
2819-
else if (prev && !on) {
2820-
// enable -> disable
2821-
jl_atomic_fetch_add(&jl_gc_disable_counter, 1);
2822-
// check if the GC is running and wait for it to finish
2823-
jl_gc_safepoint_(ptls);
2824-
}
2825-
return prev;
2826-
}
2827-
2828-
JL_DLLEXPORT int jl_gc_is_enabled(void)
2829-
{
2830-
jl_ptls_t ptls = jl_current_task->ptls;
2831-
return !ptls->disable_gc;
2832-
}
2833-
28342804
JL_DLLEXPORT void jl_gc_get_total_bytes(int64_t *bytes) JL_NOTSAFEPOINT
28352805
{
28362806
jl_gc_num_t num = gc_num;

0 commit comments

Comments
 (0)