Skip to content

Commit 248fa30

Browse files
committed
Change loads of jl_gc_disable_counter to use acquire semantics.
Stores already use seq_cst.
1 parent e4559c9 commit 248fa30

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/gc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3497,7 +3497,7 @@ JL_DLLEXPORT void jl_gc_collect(jl_gc_collection_t collection)
34973497

34983498
jl_task_t *ct = jl_current_task;
34993499
jl_ptls_t ptls = ct->ptls;
3500-
if (jl_atomic_load_relaxed(&jl_gc_disable_counter)) {
3500+
if (jl_atomic_load_acquire(&jl_gc_disable_counter)) {
35013501
size_t localbytes = jl_atomic_load_relaxed(&ptls->gc_num.allocd) + gc_num.interval;
35023502
jl_atomic_store_relaxed(&ptls->gc_num.allocd, -(int64_t)gc_num.interval);
35033503
static_assert(sizeof(_Atomic(uint64_t)) == sizeof(gc_num.deferred_alloc), "");
@@ -3548,7 +3548,7 @@ JL_DLLEXPORT void jl_gc_collect(jl_gc_collection_t collection)
35483548
gc_invoke_callbacks(jl_gc_cb_pre_gc_t,
35493549
gc_cblist_pre_gc, (collection));
35503550

3551-
if (!jl_atomic_load_relaxed(&jl_gc_disable_counter)) {
3551+
if (!jl_atomic_load_acquire(&jl_gc_disable_counter)) {
35523552
JL_LOCK_NOGC(&finalizers_lock); // all the other threads are stopped, so this does not make sense, right? otherwise, failing that, this seems like plausibly a deadlock
35533553
#ifndef __clang_gcanalyzer__
35543554
if (_jl_gc_collect(ptls, collection)) {

src/safepoint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ int jl_safepoint_start_gc(void)
127127
// Foreign thread adoption disables the GC and waits for it to finish, however, that may
128128
// introduce a race between it and this thread checking if the GC is enabled and only
129129
// then setting jl_gc_running. To avoid that, check again now that we won that race.
130-
if (jl_atomic_load_relaxed(&jl_gc_disable_counter)) {
130+
if (jl_atomic_load_acquire(&jl_gc_disable_counter)) {
131131
uv_mutex_unlock(&safepoint_lock);
132132
return 0;
133133
}

src/threading.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,11 +412,11 @@ JL_DLLEXPORT jl_gcframe_t **jl_adopt_thread(void) JL_NOTSAFEPOINT_LEAVE
412412
// we can't use a normal safepoint because we don't have signal handlers yet.
413413
// we also can't use jl_safepoint_wait_gc because that assumes we're in a task.
414414
jl_atomic_fetch_add(&jl_gc_disable_counter, 1);
415-
while (jl_atomic_load_relaxed(&jl_gc_running) || jl_atomic_load_acquire(&jl_gc_running)) {
415+
while (jl_atomic_load_acquire(&jl_gc_running)) {
416416
jl_cpu_pause();
417417
}
418418
// In `jl_safepoint_start_gc` we observe if a foreign thread has asked to disable the GC
419-
// Guaranteeing the order of events.
419+
// Guaranteeing the order of events.
420420

421421
// initialize this thread (assign tid, create heap, set up root task)
422422
jl_ptls_t ptls = jl_init_threadtls(-1);

0 commit comments

Comments
 (0)