Skip to content

Commit

Permalink
add lock around all API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyrne committed Oct 27, 2022
1 parent af62ebf commit 64f90f9
Show file tree
Hide file tree
Showing 3 changed files with 2,931 additions and 488 deletions.
8 changes: 7 additions & 1 deletion gen/bind_generator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,13 @@ function _bind(__module__, __source__, sig::Expr, err::Union{String,Expr,Nothing
# avoids inserting the line number nodes for the macro --- the call site
# is instead explicitly injected into the function body via __source__.
jlfuncsig = Expr(:call, jlfuncname, args...)
jlfuncbody = Expr(:block, __source__, :($statsym = $ccallexpr))
jlfuncbody = Expr(
:block, __source__, :(lock(liblock)), :($statsym = try
$ccallexpr
finally
unlock(liblock)
end)
)
if errexpr !== nothing
push!(jlfuncbody.args, errexpr)
end
Expand Down
2 changes: 2 additions & 0 deletions src/api/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ else
)
end

const liblock = ReentrantLock()

include("types.jl")
include("error.jl")
include("functions.jl") # core API ccall wrappers
Expand Down
Loading

0 comments on commit 64f90f9

Please sign in to comment.