lichao
2021-04-22 1d6c040dcb9a01648edc66d8c0006c8c9294a705
src/msg.h
@@ -21,6 +21,7 @@
#include "bh_util.h"
#include "proto.h"
#include "shm.h"
#include <atomic>
#include <boost/interprocess/offset_ptr.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <functional>
@@ -38,26 +39,14 @@
// store ref count, msgs shareing the same data should also hold a pointer of the same RefCount object.
class RefCount : private boost::noncopyable
{
public:
   int Inc()
   {
      Guard lk(mutex_);
      return ++num_;
   }
   int Dec()
   {
      Guard lk(mutex_);
      return --num_;
   }
   int Get()
   {
      Guard lk(mutex_);
      return num_;
   }
   std::atomic<int> num_;
private:
   Mutex mutex_;
   int num_ = 1;
public:
   RefCount() :
       num_(1) { static_assert(std::is_pod<decltype(num_)>::value); }
   int Inc() { return ++num_; }
   int Dec() { return --num_; }
   int Get() { return num_.load(); }
};
// message content layout: header_size + header + data_size + data