lichao
2021-04-25 1fbfef2a51db4a3bac9d8a5b87af94a40a913b7a
src/msg.h
@@ -23,7 +23,6 @@
#include "shm.h"
#include <atomic>
#include <boost/interprocess/offset_ptr.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <functional>
#include <stdint.h>
@@ -34,11 +33,10 @@
// ShmMsg is safe to be stored in shared memory, so POD data or offset_ptr is required.
// message content layout: (meta) / header_size + header + data_size + data
typedef boost::uuids::uuid MQId;
class ShmMsg
class ShmMsg : private StaticDataRef<SharedMemory, ShmMsg>
{
private:
   static inline SharedMemory &shm() { return GetData(); }
   // store ref count, msgs shareing the same data should also hold a pointer of the same RefCount object.
   class RefCount : private boost::noncopyable
   {
@@ -58,16 +56,6 @@
   {
      static const Offset base = Addr(shm().get_address()); // cache value.
      return base;
   }
   static inline SharedMemory &shm()
   {
      if (!pshm()) { throw std::string("Must set ShmMsg shm before use!"); }
      return *pshm();
   }
   static inline SharedMemory *&pshm()
   {
      static SharedMemory *pshm = 0;
      return pshm;
   }
   static const uint32_t kMsgTag = 0xf1e2d3c4;
@@ -145,13 +133,7 @@
   T *get() const { return static_cast<T *>(Ptr(offset_ + BaseAddr())); }
public:
   static bool BindShm(SharedMemory &shm)
   {
      assert(!pshm());
      pshm() = &shm;
      return true;
   }
   static bool BindShm(SharedMemory &shm) { return SetData(shm); }
   ShmMsg() :
       ShmMsg(nullptr) {}
   explicit ShmMsg(const size_t size) :