| | |
| | | |
| | | class ShmMsg : private StaticDataRef<SharedMemory, ShmMsg> |
| | | { |
| | | public: |
| | | static inline SharedMemory &shm() { return GetData(); } |
| | | |
| | | private: |
| | | static ShmSocket &Sender(); |
| | | |
| | | // store ref count, msgs shareing the same data should also hold a pointer of the same RefCount object. |
| | |
| | | const uint32_t size_ = 0; |
| | | const int64_t id_ = 0; |
| | | std::atomic<int64_t> timestamp_; |
| | | bool managed_ = false; |
| | | Meta(uint32_t size) : |
| | | size_(size), id_(NewId()), timestamp_(NowSec()) {} |
| | | }; |
| | |
| | | int AddRef() const { return valid() ? meta()->count_.Inc() : 1; } |
| | | int Release(); |
| | | void Free(); |
| | | void reset_managed(const bool val) const |
| | | { |
| | | if (valid()) { meta()->managed_ = val; } |
| | | } |
| | | |
| | | template <class Body> |
| | | inline bool Make(const BHMsgHead &head, const Body &body) |
| | |
| | | constexpr inline bool IsCmd(int64_t msg) { return (msg & 1) != 0; } |
| | | // int64_t pack format: cmd data ,3bit cmd, 1bit flag. |
| | | enum MsgCmd { |
| | | eCmdNodeInit = 0, // upto 59bit ssn id |
| | | eCmdNodeInit = 0, // upto 56bit ssn id |
| | | eCmdNodeInitReply = 1, // 31bit proc index, |
| | | eCmdAllocRequest0 = 2, // 8bit size, 4bit socket index, 16bit proc index, 28bit id |
| | | eCmdAllocReply0 = 3, // 31bit ptr, 28bit id, |