@@ -368,14 +368,14 @@ JL_DLLEXPORT jl_task_t *jl_task_get_next(jl_value_t *trypoptask, jl_value_t *q,
368368 JL_UV_LOCK (); // jl_mutex_lock(&jl_uv_mutex);
369369 }
370370 if (uvlock ) {
371- int active = 1 ;
372- // otherwise, we block until someone asks us for the lock
373- uv_loop_t * loop = jl_global_event_loop ();
374- while ( active && may_sleep ( ptls )) {
375- if ( jl_atomic_load_relaxed ( & jl_uv_n_waiters ) != 0 )
376- // but if we won the race against someone who actually needs
377- // the lock to do real work, we need to let them have it instead
378- break ;
371+ int enter_eventloop = may_sleep ( ptls ) ;
372+ int active = 0 ;
373+ if ( jl_atomic_load_relaxed ( & jl_uv_n_waiters ) != 0 )
374+ // if we won the race against someone who actually needs
375+ // the lock to do real work, we need to let them have it instead
376+ enter_eventloop = 0 ;
377+ if ( enter_eventloop ) {
378+ uv_loop_t * loop = jl_global_event_loop () ;
379379 loop -> stop_flag = 0 ;
380380 JULIA_DEBUG_SLEEPWAKE ( ptls -> uv_run_enter = cycleclock () );
381381 active = uv_run (loop , UV_RUN_ONCE );
@@ -388,11 +388,11 @@ JL_DLLEXPORT jl_task_t *jl_task_get_next(jl_value_t *trypoptask, jl_value_t *q,
388388 // that just wanted to steal libuv from us. We will just go
389389 // right back to sleep on the individual wake signal to let
390390 // them take it from us without conflict.
391- if (!may_sleep (ptls )) {
391+ if (active || !may_sleep (ptls )) {
392392 start_cycles = 0 ;
393393 continue ;
394394 }
395- if (!jl_atomic_load_relaxed (& _threadedregion ) && active && ptls -> tid == 0 ) {
395+ if (!enter_eventloop && ! jl_atomic_load_relaxed (& _threadedregion ) && ptls -> tid == 0 ) {
396396 // thread 0 is the only thread permitted to run the event loop
397397 // so it needs to stay alive, just spin-looping if necessary
398398 if (jl_atomic_load_relaxed (& ptls -> sleep_check_state ) != not_sleeping ) {
0 commit comments