@@ -182,6 +182,7 @@ struct chunk_info_t {
182
182
auto & chunk_storages () {
183
183
class chunk_handle_t {
184
184
ipc::unordered_map<ipc::string, ipc::shm::handle> handles_;
185
+ std::mutex lock_;
185
186
186
187
static bool make_handle (ipc::shm::handle &h, ipc::string const &shm_name, std::size_t chunk_size) {
187
188
if (!h.valid () &&
@@ -197,19 +198,25 @@ auto& chunk_storages() {
197
198
chunk_info_t *get_info (conn_info_head *inf, std::size_t chunk_size) {
198
199
ipc::string pref {(inf == nullptr ) ? ipc::string{} : inf->prefix_ };
199
200
ipc::string shm_name {ipc::make_prefix (pref, {" CHUNK_INFO__" , ipc::to_string (chunk_size)})};
200
- ipc::shm::handle &h = handles_[pref];
201
- if (!make_handle (h, shm_name, chunk_size)) {
202
- return nullptr ;
201
+ ipc::shm::handle *h;
202
+ {
203
+ std::lock_guard<std::mutex> guard {lock_};
204
+ h = &(handles_[pref]);
205
+ if (!make_handle (*h, shm_name, chunk_size)) {
206
+ return nullptr ;
207
+ }
203
208
}
204
- auto *info = static_cast <chunk_info_t *>(h. get ());
209
+ auto *info = static_cast <chunk_info_t *>(h-> get ());
205
210
if (info == nullptr ) {
206
211
ipc::error (" [chunk_storages] chunk_shm.id_info_.get failed: chunk_size = %zd\n " , chunk_size);
207
212
return nullptr ;
208
213
}
209
214
return info;
210
215
}
211
216
};
212
- static ipc::map<std::size_t , chunk_handle_t > chunk_hs;
217
+ using deleter_t = void (*)(chunk_handle_t *);
218
+ using chunk_handle_ptr_t = std::unique_ptr<chunk_handle_t , deleter_t >;
219
+ static ipc::map<std::size_t , chunk_handle_ptr_t > chunk_hs;
213
220
return chunk_hs;
214
221
}
215
222
@@ -220,13 +227,17 @@ chunk_info_t *chunk_storage_info(conn_info_head *inf, std::size_t chunk_size) {
220
227
static ipc::rw_lock lock;
221
228
IPC_UNUSED_ std::shared_lock<ipc::rw_lock> guard {lock};
222
229
if ((it = storages.find (chunk_size)) == storages.end ()) {
223
- using chunk_handle_t = std::decay_t <decltype (storages)>::value_type::second_type;
230
+ using chunk_handle_ptr_t = std::decay_t <decltype (storages)>::value_type::second_type;
231
+ using chunk_handle_t = chunk_handle_ptr_t ::element_type;
224
232
guard.unlock ();
225
233
IPC_UNUSED_ std::lock_guard<ipc::rw_lock> guard {lock};
226
- it = storages.emplace (chunk_size, chunk_handle_t {}).first ;
234
+ it = storages.emplace (chunk_size, chunk_handle_ptr_t {
235
+ ipc::mem::alloc<chunk_handle_t >(), [](chunk_handle_t *p) {
236
+ ipc::mem::destruct (p);
237
+ }}).first ;
227
238
}
228
239
}
229
- return it->second . get_info (inf, chunk_size);
240
+ return it->second -> get_info (inf, chunk_size);
230
241
}
231
242
232
243
std::pair<ipc::storage_id_t , void *> acquire_storage (conn_info_head *inf, std::size_t size, ipc::circ::cc_t conns) {
@@ -356,8 +367,7 @@ struct queue_generator {
356
367
" QU_CONN__" ,
357
368
ipc::to_string (DataSize), " __" ,
358
369
ipc::to_string (AlignSize), " __" ,
359
- name}).c_str ()} {
360
- }
370
+ name}).c_str ()} {}
361
371
362
372
void disconnect_receiver () {
363
373
bool dis = que_.disconnect ();
0 commit comments