From 7ecd6323ffedbfef92c87c02b2a8680dd53b772c Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期四, 06 五月 2021 19:37:50 +0800 Subject: [PATCH] rename atomic queue io function. --- src/shm.h | 19 +++++++++++++++---- 1 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/shm.h b/src/shm.h index 17352fe..b168413 100644 --- a/src/shm.h +++ b/src/shm.h @@ -68,7 +68,7 @@ if (Killed(old)) { r = PidCas(old, pid()); if (r) { - printf("PidCheck captured pid %d -> %d\n", old, pid()); + LOG_DEBUG() << "PidCheck captured pid " << old << " -> " << pid(); } } } @@ -90,12 +90,13 @@ } }; -typedef robust::CasMutex<true> Mutex; +typedef robust::Mutex Mutex; typedef robust::Guard<Mutex> Guard; class SharedMemory : public mshm_t { std::string name_; + Mutex *pmutex_ = 0; static permissions AllowAll() { @@ -122,19 +123,29 @@ { return construct<T>(name.c_str(), std::nothrow)(std::forward<decltype(params)>(params)...); } - void *Alloc(const size_t size) { return allocate(size, std::nothrow); } + void *Alloc(const size_t size) + { + Guard lock(*pmutex_); + return allocate(size, std::nothrow); + } void Dealloc(void *p) { + Guard lock(*pmutex_); if (p) { deallocate(p); } } template <class T> void Dealloc(offset_ptr<T> ptr) { return Dealloc(ptr.get()); } template <class T, class... Params> - T *New(Params &&...params) { return construct<T>(anonymous_instance, std::nothrow)(std::forward<decltype(params)>(params)...); } + T *New(Params &&...params) + { + Guard lock(*pmutex_); + return construct<T>(anonymous_instance, std::nothrow)(std::forward<decltype(params)>(params)...); + } template <class T> void Delete(T *p) { + Guard lock(*pmutex_); if (p) { destroy_ptr<T>(p); }; } template <class T> -- Gitblit v1.8.0