Skip to content
Snippets Groups Projects

add h5parm singleton

Merged Sarod Yatawatta requested to merge sagecalpred_h5parm_singleton into master
3 unresolved threads

libhdf5 is not always thread safe, and it is not necessary to re-read the same h5 file when multiple threads are accessing it, this fixes both issues by using a singleton for the h5 file, the h5parm is passed as a reference to all threads (so h5parm is assumed thread safe, for reading)

Edited by Sarod Yatawatta

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
130 130 #endif /* HAVE_LIBDIRAC || HAVE_LIBDIRAC_CUDA */
131 131
132 // Singleton to open and read H5 file only by one thread
133 // But H5Parm itself is assumed thread-safe
134 class H5ParmSingle {
135 private:
136 explicit H5ParmSingle() : is_opened_(false) {}
137 std::mutex mutex_;
138 bool is_opened_;
139
140 public:
141 H5ParmSingle(H5ParmSingle const&) = delete;
142 H5ParmSingle& operator=(H5ParmSingle const&) = delete;
143 ~H5ParmSingle(){};
144
145 static H5ParmSingle* get_instance() {
  • Method names should be written with camelcase according to Google Style, so GetInstance().

    Also, return value would better be H5ParmSingle& to indicate it can't be nullptr.

  • Please register or sign in to reply
  • 135 private:
    136 explicit H5ParmSingle() : is_opened_(false) {}
    137 std::mutex mutex_;
    138 bool is_opened_;
    139
    140 public:
    141 H5ParmSingle(H5ParmSingle const&) = delete;
    142 H5ParmSingle& operator=(H5ParmSingle const&) = delete;
    143 ~H5ParmSingle(){};
    144
    145 static H5ParmSingle* get_instance() {
    146 static H5ParmSingle instance;
    147 return &instance;
    148 }
    149
    150 schaapcommon::h5parm::H5Parm& open_file(const std::string& h5_name);
  • 129 129 };
    130 130 #endif /* HAVE_LIBDIRAC || HAVE_LIBDIRAC_CUDA */
    131 131
    132 // Singleton to open and read H5 file only by one thread
    133 // But H5Parm itself is assumed thread-safe
    134 class H5ParmSingle {
    135 private:
    136 explicit H5ParmSingle() : is_opened_(false) {}
    137 std::mutex mutex_;
    138 bool is_opened_;
  • Alex Kurek mentioned in issue rapthor#21

    mentioned in issue rapthor#21

  • Please register or sign in to reply
    Loading