From 66cfab4a62bf1679d6f13b2fa8d2b2e3a4f8456b Mon Sep 17 00:00:00 2001 From: mutouyun Date: Fri, 25 Jan 2019 15:02:53 +0800 Subject: [PATCH] use new for synchronized-wrapper --- src/memory/wrapper.h | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/src/memory/wrapper.h b/src/memory/wrapper.h index aeb5201..5acfca5 100644 --- a/src/memory/wrapper.h +++ b/src/memory/wrapper.h @@ -13,9 +13,6 @@ #include "def.h" #include "rw_lock.h" #include "tls_pointer.h" - -#include "memory/alloc.h" -#include "memory/detail.h" #include "platform/detail.h" namespace ipc { @@ -124,14 +121,6 @@ constexpr bool operator!=(const allocator_wrapper&, const allocator_w /// Thread-safe allocation wrapper //////////////////////////////////////////////////////////////// -template -using page_fixed = ipc::mem::detail::fixed; - -using page_pool_alloc = detail::pool_alloc; - -template -using page_allocator = allocator_wrapper; - template class synchronized { public: @@ -139,8 +128,7 @@ public: private: spin_lock lc_; - std::multimap, - page_allocator>> allocs_; + std::multimap allocs_; struct alloc_t { synchronized* t_; @@ -156,11 +144,10 @@ private: std::tie(s_, a_) = *it; t_->allocs_.erase(it); } - if (a_ == nullptr) { - a_ = static_cast(page_pool_alloc::alloc(sizeof(alloc_policy))); - } } - ::new (a_) alloc_policy; + if (a_ == nullptr) { + a_ = new alloc_policy; + } } ~alloc_t() { @@ -188,11 +175,14 @@ private: } public: + ~synchronized() { + clear(); + } + void clear() { IPC_UNUSED_ auto guard = ipc::detail::unique_lock(lc_); for (auto& pair : allocs_) { - pair.second->~AllocP(); - page_pool_alloc::free(pair.second, sizeof(alloc_policy)); + delete pair.second; } }