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

use API lock in helper function ccalls #1181

Merged
merged 4 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions src/api/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -626,9 +626,12 @@ Deprecated HDF5 function. Use [`h5o_get_info`](@ref) or [`h5o_get_native_info`](
See `libhdf5` documentation for [`H5Oget_info1`](https://portal.hdfgroup.org/display/HDF5/H5O_GET_INFO1).
"""
function h5o_get_info1(object_id, buf)
var"#status#" = ccall(
(:H5Oget_info1, libhdf5), herr_t, (hid_t, Ptr{H5O_info_t}), object_id, buf
)
lock(liblock)
var"#status#" = try
ccall((:H5Oget_info1, libhdf5), herr_t, (hid_t, Ptr{H5O_info_t}), object_id, buf)
finally
unlock(liblock)
end
var"#status#" < 0 && @h5error("Error getting object info")
return nothing
end
Expand Down Expand Up @@ -876,7 +879,12 @@ end
See `libhdf5` documentation for [`H5P_GET_CLASS_NAME`](https://portal.hdfgroup.org/display/HDF5/H5P_GET_CLASS_NAME).
"""
function h5p_get_class_name(pcid)
pc = ccall((:H5Pget_class_name, libhdf5), Ptr{UInt8}, (hid_t,), pcid)
lock(liblock)
pc = try
ccall((:H5Pget_class_name, libhdf5), Ptr{UInt8}, (hid_t,), pcid)
finally
unlock(liblock)
end
if pc == C_NULL
@h5error("Error getting class name")
end
Expand Down Expand Up @@ -987,7 +995,12 @@ end
See `libhdf5` documentation for [`H5Oopen`](https://portal.hdfgroup.org/display/HDF5/H5T_GET_MEMBER_NAME).
"""
function h5t_get_member_name(type_id, index)
pn = ccall((:H5Tget_member_name, libhdf5), Ptr{UInt8}, (hid_t, Cuint), type_id, index)
lock(liblock)
pn = try
ccall((:H5Tget_member_name, libhdf5), Ptr{UInt8}, (hid_t, Cuint), type_id, index)
finally
unlock(liblock)
end
if pn == C_NULL
@h5error("Error getting name of compound datatype member #$index")
end
Expand All @@ -1002,7 +1015,12 @@ end
See `libhdf5` documentation for [`H5Oopen`](https://portal.hdfgroup.org/display/HDF5/H5T_GET_TAG).
"""
function h5t_get_tag(type_id)
pc = ccall((:H5Tget_tag, libhdf5), Ptr{UInt8}, (hid_t,), type_id)
lock(liblock)
pc = try
ccall((:H5Tget_tag, libhdf5), Ptr{UInt8}, (hid_t,), type_id)
finally
unlock(liblock)
end
if pc == C_NULL
@h5error("Error getting opaque tag")
end
Expand Down
12 changes: 12 additions & 0 deletions test/apilock.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Pkg, Test
@testset "issue1179" begin
@test try
run(
`$(Base.julia_cmd()) --project=$(dirname(Pkg.project().path)) -t 6 $(joinpath(@__DIR__, "issue1179.jl"))`
)
true
catch err
@info err
false
end
end
13 changes: 13 additions & 0 deletions test/issue1179.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using HDF5

T = ComplexF64
# T = Float64 # OK
sizes = (100, 100, 100)
Threads.@threads for i in 1:Threads.nthreads()
h5open("file$i.hdf5", "w") do h5
d = create_dataset(h5, "rand", T, sizes)
for n in 1:sizes[3]
d[:, :, n] = rand(T, sizes[1:2])
end
end
end
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ end
@debug "virtual datasets"
include("virtual_dataset.jl")
end
@debug "api lock"
include("apilock.jl")

# basic MPI tests, for actual parallel tests we need to run in MPI mode
include("mpio.jl")
Expand Down
Loading