lichao
2021-04-30 95bd9a67f9f6c90f627784e3f8fbf5c203784e51
src/msg.h
@@ -49,26 +49,29 @@
      int Dec() { return --num_; }
      int Get() { return num_.load(); }
   };
   typedef int64_t Offset;
   static Offset Addr(void *ptr) { return reinterpret_cast<Offset>(ptr); }
   static void *Ptr(const Offset offset) { return reinterpret_cast<void *>(offset); }
   static inline Offset BaseAddr()
   typedef int64_t OffsetType;
   static OffsetType Addr(void *ptr) { return reinterpret_cast<OffsetType>(ptr); }
   static void *Ptr(const OffsetType offset) { return reinterpret_cast<void *>(offset); }
   static inline OffsetType BaseAddr()
   {
      static const Offset base = Addr(shm().get_address()); // cache value.
      static const OffsetType base = Addr(shm().get_address()); // cache value.
      return base;
   }
   static const uint32_t kMsgTag = 0xf1e2d3c4;
   typedef struct {
   struct Meta {
      RefCount count_;
      const uint32_t tag_ = kMsgTag;
   } Meta;
   Offset offset_;
      const uint32_t size_ = 0;
      Meta(uint32_t size) :
          size_(size) {}
   };
   OffsetType offset_;
   void *Alloc(const size_t size)
   {
      void *p = shm().Alloc(sizeof(Meta) + size);
      if (p) {
         auto pmeta = new (p) Meta;
         auto pmeta = new (p) Meta(size);
         p = pmeta + 1;
      }
      return p;
@@ -136,8 +139,10 @@
   static bool BindShm(SharedMemory &shm) { return SetData(shm); }
   ShmMsg() :
       ShmMsg(nullptr) {}
   explicit ShmMsg(const size_t size) :
       ShmMsg(Alloc(size)) {}
   explicit ShmMsg(const OffsetType offset) :
       offset_(offset) {}
   OffsetType Offset() const { return offset_; }
   OffsetType &OffsetRef() { return offset_; }
   void swap(ShmMsg &a) { std::swap(offset_, a.offset_); }
   bool valid() const { return static_cast<bool>(offset_) && meta()->tag_ == kMsgTag; }