File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -131,7 +131,7 @@ struct chunk_info_t {
131131};
132132
133133auto & chunk_storages () {
134- class chunk_t {
134+ class chunk_handle_t {
135135 ipc::shm::handle handle_;
136136
137137 public:
@@ -150,12 +150,24 @@ auto& chunk_storages() {
150150 return info;
151151 }
152152 };
153- thread_local ipc::unordered_map <std::size_t , chunk_t > chunk_s ;
154- return chunk_s ;
153+ static ipc::map <std::size_t , chunk_handle_t > chunk_hs ;
154+ return chunk_hs ;
155155}
156156
157157chunk_info_t *chunk_storage_info (std::size_t chunk_size) {
158- return chunk_storages ()[chunk_size].get_info (chunk_size);
158+ auto &storages = chunk_storages ();
159+ std::decay_t <decltype (storages)>::iterator it;
160+ {
161+ static ipc::rw_lock lock;
162+ IPC_UNUSED_ std::shared_lock<ipc::rw_lock> guard {lock};
163+ if ((it = storages.find (chunk_size)) == storages.end ()) {
164+ using chunk_handle_t = std::decay_t <decltype (storages)>::value_type::second_type;
165+ guard.unlock ();
166+ IPC_UNUSED_ std::lock_guard<ipc::rw_lock> guard {lock};
167+ it = storages.emplace (chunk_size, chunk_handle_t {}).first ;
168+ }
169+ }
170+ return it->second .get_info (chunk_size);
159171}
160172
161173std::pair<ipc::storage_id_t , void *> acquire_storage (std::size_t size, ipc::circ::cc_t conns) {
You can’t perform that action at this time.
0 commit comments