From bbbcc4fed67337c038b485f00677e2e88d24becd Mon Sep 17 00:00:00 2001 From: Gabriel Baraldi Date: Sat, 9 Sep 2023 17:43:01 -0300 Subject: [PATCH] Add lock around uv_unref during init (#51236) This is not a legal operation outside the lock because it's not atomic Co-authored-by: Valentin Churavy --- base/libuv.jl | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/base/libuv.jl b/base/libuv.jl index 24a04f5bcad78..4c56af29e7e60 100644 --- a/base/libuv.jl +++ b/base/libuv.jl @@ -103,8 +103,17 @@ uv_error(prefix::AbstractString, c::Integer) = c < 0 ? throw(_UVError(prefix, c) eventloop() = ccall(:jl_global_event_loop, Ptr{Cvoid}, ()) -uv_unref(h::Ptr{Cvoid}) = ccall(:uv_unref, Cvoid, (Ptr{Cvoid},), h) -uv_ref(h::Ptr{Cvoid}) = ccall(:uv_ref, Cvoid, (Ptr{Cvoid},), h) +function uv_unref(h::Ptr{Cvoid}) + iolock_begin() + ccall(:uv_unref, Cvoid, (Ptr{Cvoid},), h) + iolock_end() +end + +function uv_ref(h::Ptr{Cvoid}) + iolock_begin() + ccall(:uv_ref, Cvoid, (Ptr{Cvoid},), h) + iolock_end() +end function process_events() return ccall(:jl_process_events, Int32, ())