@@ -495,7 +495,7 @@ static void jl_gc_run_finalizers_in_list(jl_task_t *ct, arraylist_t *list) JL_NO
495495 jl_gc_push_arraylist (ct , list );
496496 void * * items = list -> items ;
497497 size_t len = list -> len ;
498- JL_UNLOCK_NOGC (& finalizers_lock );
498+ JL_SPIN_UNLOCK_NOGC (& finalizers_lock );
499499 // run finalizers in reverse order they were added, so lower-level finalizers run last
500500 for (size_t i = len - 4 ; i >= 2 ; i -= 2 )
501501 run_finalizer (ct , items [i ], items [i + 1 ]);
@@ -524,9 +524,9 @@ static void run_finalizers(jl_task_t *ct)
524524 // will flush it.
525525 if (to_finalize .len == 0 )
526526 return ;
527- JL_LOCK_NOGC (& finalizers_lock );
527+ JL_SPIN_LOCK_NOGC (& finalizers_lock );
528528 if (to_finalize .len == 0 ) {
529- JL_UNLOCK_NOGC (& finalizers_lock );
529+ JL_SPIN_UNLOCK_NOGC (& finalizers_lock );
530530 return ;
531531 }
532532 arraylist_t copied_list ;
@@ -661,14 +661,14 @@ void jl_gc_add_finalizer_(jl_ptls_t ptls, void *v, void *f) JL_NOTSAFEPOINT
661661 // between the acquire and the release of the length.
662662 size_t oldlen = jl_atomic_load_acquire ((_Atomic (size_t )* )& a -> len );
663663 if (__unlikely (oldlen + 2 > a -> max )) {
664- JL_LOCK_NOGC (& finalizers_lock );
664+ JL_SPIN_LOCK_NOGC (& finalizers_lock );
665665 // `a->len` might have been modified.
666666 // Another possibility is to always grow the array to `oldlen + 2` but
667667 // it's simpler this way and uses slightly less memory =)
668668 oldlen = a -> len ;
669669 arraylist_grow (a , 2 );
670670 a -> len = oldlen ;
671- JL_UNLOCK_NOGC (& finalizers_lock );
671+ JL_SPIN_UNLOCK_NOGC (& finalizers_lock );
672672 }
673673 void * * items = a -> items ;
674674 items [oldlen ] = v ;
@@ -700,7 +700,7 @@ JL_DLLEXPORT void jl_gc_add_finalizer_th(jl_ptls_t ptls, jl_value_t *v, jl_funct
700700
701701JL_DLLEXPORT void jl_finalize_th (jl_task_t * ct , jl_value_t * o )
702702{
703- JL_LOCK_NOGC (& finalizers_lock );
703+ JL_SPIN_LOCK_NOGC (& finalizers_lock );
704704 // Copy the finalizers into a temporary list so that code in the finalizer
705705 // won't change the list as we loop through them.
706706 // This list is also used as the GC frame when we are running the finalizers
@@ -725,7 +725,7 @@ JL_DLLEXPORT void jl_finalize_th(jl_task_t *ct, jl_value_t *o)
725725 jl_gc_run_finalizers_in_list (ct , & copied_list );
726726 }
727727 else {
728- JL_UNLOCK_NOGC (& finalizers_lock );
728+ JL_SPIN_UNLOCK_NOGC (& finalizers_lock );
729729 }
730730 arraylist_free (& copied_list );
731731}
@@ -3297,7 +3297,7 @@ JL_DLLEXPORT void jl_gc_collect(jl_gc_collection_t collection)
32973297 gc_cblist_pre_gc , (collection ));
32983298
32993299 if (!jl_atomic_load_relaxed (& jl_gc_disable_counter )) {
3300- 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
3300+ JL_SPIN_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
33013301#ifndef __clang_gcanalyzer__
33023302 if (_jl_gc_collect (ptls , collection )) {
33033303 // recollect
@@ -3306,7 +3306,7 @@ JL_DLLEXPORT void jl_gc_collect(jl_gc_collection_t collection)
33063306 assert (!ret );
33073307 }
33083308#endif
3309- JL_UNLOCK_NOGC (& finalizers_lock );
3309+ JL_SPIN_UNLOCK_NOGC (& finalizers_lock );
33103310 }
33113311
33123312 gc_n_threads = 0 ;
@@ -3399,8 +3399,8 @@ void jl_init_thread_heap(jl_ptls_t ptls)
33993399void jl_gc_init (void )
34003400{
34013401
3402- JL_MUTEX_INIT (& heapsnapshot_lock , "heapsnapshot_lock" );
3403- JL_MUTEX_INIT (& finalizers_lock , "finalizers_lock" );
3402+ JL_SPIN_MUTEX_INIT (& heapsnapshot_lock , "heapsnapshot_lock" );
3403+ JL_SPIN_MUTEX_INIT (& finalizers_lock , "finalizers_lock" );
34043404 uv_mutex_init (& gc_cache_lock );
34053405 uv_mutex_init (& gc_perm_lock );
34063406
0 commit comments