Skip to content

Commit 92873e4

Browse files
committed
Remove at-spinlock.
Locks taken in a finalizer should never be contended, as ReentrantLock inhibits finalizers when they're taken from a non-finalizer task.
1 parent 6598a1a commit 92873e4

File tree

4 files changed

+6
-28
lines changed

4 files changed

+6
-28
lines changed

lib/cudadrv/memory.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ function __pin(ptr::Ptr{Nothing}, sz::Int)
663663
ctx = context()
664664
key = (ctx,ptr)
665665

666-
@lock __pin_lock begin
666+
Base.@lock __pin_lock begin
667667
pin_count = if haskey(__pin_count, key)
668668
__pin_count[key] += 1
669669
else
@@ -687,7 +687,7 @@ end
687687
function __unpin(ptr::Ptr{Nothing}, ctx::CuContext)
688688
key = (ctx,ptr)
689689

690-
@spinlock __pin_lock begin
690+
Base.@lock __pin_lock begin
691691
@assert haskey(__pin_count, key) "Cannot unpin unmanaged pointer $ptr."
692692
pin_count = __pin_count[key] -= 1
693693
@assert pin_count >= 0 "Double unpin for $ptr"

lib/cudnn/CUDNN.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function log_message(sev, udata, dbg_ptr, ptr)
121121
str = unsafe_string(ptr, len) # XXX: can this yield?
122122

123123
# print asynchronously
124-
@spinlock log_lock begin
124+
Base.@lock log_lock begin
125125
push!(log_messages, (; sev, dbg, str))
126126
end
127127
ccall(:uv_async_send, Cint, (Ptr{Cvoid},), udata)
@@ -153,7 +153,7 @@ function __runtime_init__()
153153
if (isdebug(:init, CUDNN) || Base.JLOptions().debug_level >= 2) &&
154154
version() >= v"8.2" # NVIDIA bug #3256123
155155
log_cond[] = Base.AsyncCondition() do async_cond
156-
message = @lock log_lock popfirst!(log_messages)
156+
message = Base.@lock log_lock popfirst!(log_messages)
157157
_log_message(message...)
158158
end
159159

lib/utils/cache.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ end
4646

4747
# put a handle in the cache, or destroy it if it doesn't fit
4848
function Base.push!(f::Function, cache::HandleCache{K,V}, key::K, handle::V) where {K,V}
49-
# XXX: take this lock in a normal way once we have JuliaLang/julia#35689
50-
@spinlock cache.lock begin
49+
lock(cache.lock) do
5150
delete!(cache.active_handles, key=>handle)
5251

5352
if haskey(cache.idle_handles, key)

lib/utils/threading.jl

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,4 @@
1-
export @spinlock, @lock, LazyInitialized
2-
3-
const var"@lock" = Base.var"@lock"
4-
5-
# a safe way to acquire locks from finalizers, where we can't wait (which switches tasks)
6-
macro spinlock(l, ex)
7-
quote
8-
temp = $(esc(l))
9-
while !trylock(temp)
10-
ccall(:jl_cpu_pause, Cvoid, ())
11-
# Temporary solution before we have gc transition support in codegen.
12-
ccall(:jl_gc_safepoint, Cvoid, ())
13-
# we can't yield here
14-
end
15-
try
16-
$(esc(ex))
17-
finally
18-
unlock(temp)
19-
end
20-
end
21-
end
22-
1+
export LazyInitialized
232

243
"""
254
LazyInitialized{T}()

0 commit comments

Comments
 (0)