@@ -125,8 +125,8 @@ class mutex {
125125 IPC_UNUSED_ std::lock_guard<std::mutex> guard {info.lock };
126126 auto it = info.mutex_handles .find (name);
127127 if (it == info.mutex_handles .end ()) {
128- it = curr_prog::get () .mutex_handles .emplace (name,
129- curr_prog::shm_data::init{name}).first ;
128+ it = info .mutex_handles .emplace (name,
129+ curr_prog::shm_data::init{name}).first ;
130130 }
131131 mutex_ = &it->second .mtx ;
132132 ref_ = &it->second .ref ;
@@ -135,20 +135,26 @@ class mutex {
135135 template <typename F>
136136 void release_mutex (ipc::string const &name, F &&clear) {
137137 if (name.empty ()) return ;
138- IPC_UNUSED_ std::lock_guard<std::mutex> guard {curr_prog::get ().lock };
139- auto it = curr_prog::get ().mutex_handles .find (name);
140- if (it == curr_prog::get ().mutex_handles .end ()) {
138+ auto &info = curr_prog::get ();
139+ IPC_UNUSED_ std::lock_guard<std::mutex> guard {info.lock };
140+ auto it = info.mutex_handles .find (name);
141+ if (it == info.mutex_handles .end ()) {
141142 return ;
142143 }
143144 if (clear ()) {
144- curr_prog::get () .mutex_handles .erase (it);
145+ info .mutex_handles .erase (it);
145146 }
146147 }
147148
148149public:
149150 mutex () = default ;
150151 ~mutex () = default ;
151152
153+ static void init () {
154+ // Avoid exception problems caused by static member initialization order.
155+ curr_prog::get ();
156+ }
157+
152158 a0_mtx_t const *native () const noexcept {
153159 return valid () ? mutex_->native () : nullptr ;
154160 }
0 commit comments