Skip to content

Commit f7f82b0

Browse files
authored
Merge pull request #96 from mmtk/dcn-refactor-preserve-and-unpreserve_handle
make preserve/unpreserve_handle use the pin/unpin_count functions
2 parents d2f7ee7 + a29d4f4 commit f7f82b0

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

base/libuv.jl

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,32 @@ iolock_end() = ccall(:jl_iolock_end, Cvoid, ())
6060
const uvhandles = IdDict()
6161
const preserve_handle_lock = Threads.SpinLock()
6262
@nospecializeinfer function preserve_handle(@nospecialize(x))
63-
lock(preserve_handle_lock)
64-
v = get(uvhandles, x, 0)::Int
65-
uvhandles[x] = v + 1
66-
unlock(preserve_handle_lock)
63+
@static if Base.USING_STOCK_GC
64+
lock(preserve_handle_lock)
65+
v = get(uvhandles, x, 0)::Int
66+
uvhandles[x] = v + 1
67+
unlock(preserve_handle_lock)
68+
else
69+
Base.increment_tpin_count!(x)
70+
end
6771
nothing
6872
end
6973
@nospecializeinfer function unpreserve_handle(@nospecialize(x))
70-
lock(preserve_handle_lock)
71-
v = get(uvhandles, x, 0)::Int
72-
if v == 0
74+
@static if Base.USING_STOCK_GC
75+
lock(preserve_handle_lock)
76+
v = get(uvhandles, x, 0)::Int
77+
if v == 0
78+
unlock(preserve_handle_lock)
79+
error("unbalanced call to unpreserve_handle for $(typeof(x))")
80+
elseif v == 1
81+
pop!(uvhandles, x)
82+
else
83+
uvhandles[x] = v - 1
84+
end
7385
unlock(preserve_handle_lock)
74-
error("unbalanced call to unpreserve_handle for $(typeof(x))")
75-
elseif v == 1
76-
pop!(uvhandles, x)
7786
else
78-
uvhandles[x] = v - 1
87+
Base.decrement_tpin_count!(x)
7988
end
80-
unlock(preserve_handle_lock)
8189
nothing
8290
end
8391

0 commit comments

Comments
 (0)