diff --git a/src/jl_uv.c b/src/jl_uv.c index 5aa5c3ddf0962..3ca423171d4d3 100644 --- a/src/jl_uv.c +++ b/src/jl_uv.c @@ -190,6 +190,8 @@ JL_DLLEXPORT void jl_uv_req_set_data(uv_req_t *req, void *data) { req->data = da JL_DLLEXPORT void *jl_uv_handle_data(uv_handle_t *handle) { return handle->data; } JL_DLLEXPORT void *jl_uv_write_handle(uv_write_t *req) { return req->handle; } +extern volatile unsigned _threadedregion; + JL_DLLEXPORT int jl_run_once(uv_loop_t *loop) { jl_ptls_t ptls = jl_get_ptls_states(); @@ -207,13 +209,14 @@ JL_DLLEXPORT int jl_run_once(uv_loop_t *loop) JL_DLLEXPORT int jl_process_events(uv_loop_t *loop) { jl_ptls_t ptls = jl_get_ptls_states(); - if (loop) { + if (loop && (_threadedregion || ptls->tid == 0)) { jl_gc_safepoint_(ptls); - JL_UV_LOCK(); - loop->stop_flag = 0; - int r = uv_run(loop,UV_RUN_NOWAIT); - JL_UV_UNLOCK(); - return r; + if (jl_mutex_trylock(&jl_uv_mutex)) { + loop->stop_flag = 0; + int r = uv_run(loop,UV_RUN_NOWAIT); + JL_UV_UNLOCK(); + return r; + } } return 0; } diff --git a/src/partr.c b/src/partr.c index 4c8fc326e2195..7f2133844564e 100644 --- a/src/partr.c +++ b/src/partr.c @@ -243,9 +243,11 @@ JL_DLLEXPORT void jl_enqueue_task(jl_task_t *task) // get the next runnable task from the multiq static jl_task_t *get_next_task(jl_value_t *getsticky) { + jl_gc_safepoint(); jl_task_t *task = (jl_task_t*)jl_apply(&getsticky, 1); if (jl_typeis(task, jl_task_type)) return task; + jl_gc_safepoint(); return multiq_deletemin(); } @@ -258,7 +260,6 @@ JL_DLLEXPORT jl_task_t *jl_task_get_next(jl_value_t *getsticky) jl_task_t *task; while (1) { - jl_gc_safepoint(); task = get_next_task(getsticky); if (task) return task;