Skip to content

Commit fd8002c

Browse files
committed
avoid locking in generated function preamble
1 parent 8d82e2a commit fd8002c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Convert/pyconvert.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,12 @@ pyconvert_fix(::Type{T}, func) where {T} = x -> func(T, x)
309309

310310
const PYCONVERT_RULES_CACHE = Lockable(Dict{Type,Dict{C.PyPtr,Vector{Function}}}())
311311

312-
@generated pyconvert_rules_cache(::Type{T}) where {T} =
313-
Base.@lock PYCONVERT_RULES_CACHE get!(Dict{C.PyPtr,Vector{Function}}, PYCONVERT_RULES_CACHE[], T)
312+
function pyconvert_rules_cache(::Type{T}) where {T}
313+
Base.@lock PYCONVERT_RULES_CACHE _pyconvert_rules_cache!(T)
314+
end
315+
@generated function _pyconvert_rules_cache!(::Type{T}) where {T}
316+
get!(() -> Dict{C.PyPtr,Vector{Function}}(), PYCONVERT_RULES_CACHE[], T)
317+
end
314318

315319
function pyconvert_rule_fast(::Type{T}, x::Py) where {T}
316320
if T isa Union

0 commit comments

Comments
 (0)