From 2197cf91e7a3bd5941327ba630a42946b88f069e Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期五, 09 四月 2021 14:15:41 +0800 Subject: [PATCH] join pub/sub to node; refactor. --- src/msg.h | 26 ++++++++++---------------- 1 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/msg.h b/src/msg.h index 661d989..10ad0d2 100644 --- a/src/msg.h +++ b/src/msg.h @@ -105,27 +105,21 @@ bool IsCounted() const { return static_cast<bool>(count_); } template <class Body> - bool Make(SharedMemory &shm, const BHMsgHead &head, const Body &body) - { - return Make(shm, Pack(shm, head, body)); - } - template <class Body> - bool MakeRC(SharedMemory &shm, const BHMsgHead &head, const Body &body) + inline bool MakeRC(SharedMemory &shm, const BHMsgHead &head, const Body &body) { return MakeRC(shm, Pack(shm, head, body)); } - bool MakeRC(SharedMemory &shm, MsgI &a) + + bool EnableRefCount(SharedMemory &shm); + + template <class Body> + inline bool Make(SharedMemory &shm, const BHMsgHead &head, const Body &body) { - if (a.IsCounted()) { - *this = a; - AddRef(); - return true; - } else { - void *p = a.ptr_.get(); - a.ptr_ = 0; - return MakeRC(shm, p); - } + void *p = Pack(shm, head, body); + auto NeedRefCount = [&]() { return head.type() == kMsgTypePublish; }; + return NeedRefCount() ? MakeRC(shm, p) : Make(shm, p); } + bool ParseHead(BHMsgHead &head) const; template <class Body> bool ParseBody(Body &body) const -- Gitblit v1.8.0