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 {
131
131
};
132
132
133
133
auto & chunk_storages () {
134
- class chunk_t {
134
+ class chunk_handle_t {
135
135
ipc::shm::handle handle_;
136
136
137
137
public:
@@ -150,12 +150,24 @@ auto& chunk_storages() {
150
150
return info;
151
151
}
152
152
};
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 ;
155
155
}
156
156
157
157
chunk_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);
159
171
}
160
172
161
173
std::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