Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Lock Preferences #1022

Closed
wants to merge 14 commits into from
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
HDF5_jll = "0234f1f7-429e-5d53-9886-15a909be8d59"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Mmap = "a63ad114-7e13-5084-954f-fe012c677804"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"

[compat]
Compat = "3.1.0, 4"
HDF5_jll = "~1.10.5, ~1.12.0"
Requires = "1.0"
Preferences = "1.3"
julia = "1.3"

[extras]
Expand Down
7 changes: 5 additions & 2 deletions gen/bind_generator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,13 @@ function _bind(__module__, __source__, sig::Expr, err::Union{String,Expr,Nothing
# is instead explicitly injected into the function body via __source__.
jlfuncsig = Expr(:call, jlfuncname, args...)
jlfuncbody = Expr(
:block, __source__, :(lock(liblock)), :($statsym = try
:block,
__source__,
:(use_api_lock && lock(liblock)),
:($statsym = try
$ccallexpr
finally
unlock(liblock)
use_api_lock && unlock(liblock)
end)
)
if errexpr !== nothing
Expand Down
14 changes: 11 additions & 3 deletions src/api/api.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
"""
HDF5.API

Low-level API module with configurable locking mechanism to support
multithreading.
"""
module API

import Libdl
@static if VERSION >= v"1.6"
import Preferences
end
using Base: StringVector

const depsfile = joinpath(@__DIR__, "..", "..", "deps", "deps.jl")
Expand All @@ -13,8 +22,7 @@ else
)
end

const liblock = ReentrantLock()

include("lock.jl")
include("types.jl")
include("error.jl")
include("functions.jl") # core API ccall wrappers
Expand All @@ -37,7 +45,7 @@ function __init__()
end

# use our own error handling machinery (i.e. turn off automatic error printing)
h5e_set_auto(API.H5E_DEFAULT, C_NULL, C_NULL)
h5e_set_auto(H5E_DEFAULT, C_NULL, C_NULL)
end

end # module API
2 changes: 1 addition & 1 deletion src/api/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Base.isempty(err::H5Error) = length(err) == 0
function H5Error(msg::AbstractString)
id = h5e_get_current_stack()
err = H5Error(msg, id)
finalizer(close, err)
finalizer(lock_and_close, err)
return err
end

Expand Down
Loading