| | |
| | | #ifndef SHM_6CHO6D6C |
| | | #define SHM_6CHO6D6C |
| | | |
| | | #include "robust.h" |
| | | #include "log.h" |
| | | #include <atomic> |
| | | #include <boost/interprocess/managed_shared_memory.hpp> |
| | | #include <boost/interprocess/sync/interprocess_mutex.hpp> |
| | |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | }; |
| | | |
| | | typedef robust::CasMutex<true> Mutex; |
| | | typedef robust::Guard<Mutex> Guard; |
| | | typedef interprocess_mutex Mutex; |
| | | typedef scoped_lock<Mutex> Guard; |
| | | // typedef robust::Guard<Mutex> Guard; |
| | | |
| | | class SharedMemory : public mshm_t |
| | | { |
| | | std::string name_; |
| | | Mutex *pmutex_ = 0; |
| | | |
| | | static permissions AllowAll() |
| | | { |
| | |
| | | { |
| | | 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> |