From 2e2cf82d91a09fcb661d9f979bb4c20d0936cfac Mon Sep 17 00:00:00 2001 From: zhangyi Date: Thu, 28 Mar 2019 13:04:29 +0800 Subject: [PATCH] add dismiss for shm --- include/shm.h | 1 + src/platform/shm_win.cpp | 2 +- src/shm.cpp | 16 +++++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/include/shm.h b/include/shm.h index 8430469..b5206c6 100644 --- a/include/shm.h +++ b/include/shm.h @@ -38,6 +38,7 @@ public: void release(); void* get() const; + id_t dismiss(); private: class handle_; diff --git a/src/platform/shm_win.cpp b/src/platform/shm_win.cpp index 175f307..afb3bb2 100644 --- a/src/platform/shm_win.cpp +++ b/src/platform/shm_win.cpp @@ -75,7 +75,7 @@ void * get_mem(id_t id, std::size_t * size) { ipc::error("fail MapViewOfFile[%d]\n", static_cast(::GetLastError())); return nullptr; } - PMEMORY_BASIC_INFORMATION mem_info; + MEMORY_BASIC_INFORMATION mem_info; if (::VirtualQuery(mem, &mem_info, sizeof(mem_info)) == 0) { ipc::error("fail VirtualQuery[%d]\n", static_cast(::GetLastError())); return nullptr; diff --git a/src/shm.cpp b/src/shm.cpp index 37227c1..3b035a7 100644 --- a/src/shm.cpp +++ b/src/shm.cpp @@ -66,11 +66,7 @@ bool handle::acquire(char const * name, std::size_t size, unsigned mode) { void handle::release() { if (!valid()) return; - shm::release(impl(p_)->id_); - impl(p_)->id_ = nullptr; - impl(p_)->m_ = nullptr; - impl(p_)->s_ = 0; - impl(p_)->n_.clear(); + shm::release(dismiss()); } void* handle::get() const { @@ -78,5 +74,15 @@ void* handle::get() const { return impl(p_)->m_; } +id_t handle::dismiss() { + if (!valid()) return nullptr; + auto old = impl(p_)->id_; + impl(p_)->id_ = nullptr; + impl(p_)->m_ = nullptr; + impl(p_)->s_ = 0; + impl(p_)->n_.clear(); + return old; +} + } // namespace shm } // namespace ipc