Skip to content
Open
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
2 changes: 1 addition & 1 deletion doc/developer_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ is a sensible thing to do. We assume similar about `bool` and
Anything `H5Easy` related goes in files with the appropriate name.

#### Everything Else
What's left goes in `tests/unit/test_high_five_base.cpp`. This covers opening
What's left goes in `tests/unit/tests_high_five_base.cpp`. This covers opening
files, groups, dataset or attributes; checking certain pathological edge cases;
etc.

Expand Down
21 changes: 21 additions & 0 deletions include/highfive/H5PropertyList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,27 @@ class AttributePhaseChange {
unsigned _min_dense;
};

///
/// \brief Set locking FileAccessProps
///
/// Since HDF5 in version 1.10.0, `single-writer / multiple-readers` support was added.
/// To achieve this, locks were added when accessing the file.
/// They can be disabled with the `HDF5_USE_FILE_LOCKING` environment variable.
/// However, if it's known at access time that one will never have another process writing the file,
/// the locks can be avoided.
///
/// See more in https://support.hdfgroup.org/documentation/hdf5/latest/_file_lock.html
///
class FileLocking {
public:
explicit FileLocking(bool use_file_locking, bool ignore_when_disabled);
void apply(const hid_t list) const;
private:
friend FileAccessProps;
bool _use_file_locking;
bool _ignore_when_disabled;
};

/// @}

} // namespace HighFive
Expand Down
7 changes: 7 additions & 0 deletions include/highfive/bits/H5PropertyList_misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,5 +501,12 @@ inline void AttributePhaseChange::apply(hid_t hid) const {
detail::h5p_set_attr_phase_change(hid, _max_compact, _min_dense);
}

inline FileLocking::FileLocking(bool use_file_locking, bool ignore_when_disabled)
: _use_file_locking(use_file_locking)
, _ignore_when_disabled(ignore_when_disabled) { }

inline void FileLocking::apply(hid_t hid) const {
detail::h5p_set_file_locking(hid, _use_file_locking, _ignore_when_disabled);
}

} // namespace HighFive
8 changes: 8 additions & 0 deletions include/highfive/bits/h5p_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,14 @@ inline herr_t h5p_set_attr_phase_change(hid_t plist_id, unsigned max_compact, un
return err;
}

inline herr_t h5p_set_file_locking(hid_t plist_id, bool use_file_locking, bool ignore_when_disabled) {
herr_t err = H5Pset_file_locking(plist_id, use_file_locking, ignore_when_disabled);
if (err < 0) {
HDF5ErrMapper::ToException<PropertyException>("Unable to set locking");
}
return err;
}


} // namespace detail
} // namespace HighFive
11 changes: 11 additions & 0 deletions tests/unit/tests_high_five_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,17 @@ TEST_CASE("AttributePhaseChange") {
}
}

TEST_CASE("Locking") {
auto fapl = HighFive::FileAccessProps::Default();
fapl.add(HighFive::FileLocking(true, false));
std::string path = "openmodes.h5";
HighFive::File file(path, HighFive::File::ReadOnly, fapl);

// can't open the same file twice with different locking
CHECK_THROWS_AS(HighFive::File(path), FileException);
}


TEST_CASE("datasetOffset") {
std::string filename = "datasetOffset.h5";
std::string dsetname = "dset";
Expand Down