Skip to content

Commit

Permalink
use API lock in helper function ccalls (#1181)
Browse files Browse the repository at this point in the history
* use API lock in helper function ccalls

* apply format

* add issue1179 test

* format
  • Loading branch information
lxvm authored Nov 20, 2024
1 parent e0eedc3 commit ebaaeee
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
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

0 comments on commit ebaaeee

Please sign in to comment.