From 1bb96fe2f152b1e46858435272ecffb3ce915242 Mon Sep 17 00:00:00 2001 From: mutouyun Date: Sun, 11 Jul 2021 23:01:36 +0800 Subject: [PATCH] update chunk_storage_info --- src/ipc.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/ipc.cpp b/src/ipc.cpp index a9916ce..dcf60b3 100755 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -131,7 +131,7 @@ struct chunk_info_t { }; auto& chunk_storages() { - class chunk_t { + class chunk_handle_t { ipc::shm::handle handle_; public: @@ -150,12 +150,24 @@ auto& chunk_storages() { return info; } }; - thread_local ipc::unordered_map chunk_s; - return chunk_s; + static ipc::map chunk_hs; + return chunk_hs; } chunk_info_t *chunk_storage_info(std::size_t chunk_size) { - return chunk_storages()[chunk_size].get_info(chunk_size); + auto &storages = chunk_storages(); + std::decay_t::iterator it; + { + static ipc::rw_lock lock; + IPC_UNUSED_ std::shared_lock guard {lock}; + if ((it = storages.find(chunk_size)) == storages.end()) { + using chunk_handle_t = std::decay_t::value_type::second_type; + guard.unlock(); + IPC_UNUSED_ std::lock_guard guard {lock}; + it = storages.emplace(chunk_size, chunk_handle_t{}).first; + } + } + return it->second.get_info(chunk_size); } std::pair acquire_storage(std::size_t size, ipc::circ::cc_t conns) {