From 77a6c3512a44dfe6540dde71946e6484fe4f173f Mon Sep 17 00:00:00 2001
From: lichao <lichao@aiotlink.com>
Date: 星期一, 10 五月 2021 16:05:28 +0800
Subject: [PATCH] test lock code.

---
 src/msg.cpp |   60 +++---------------------------------------------------------
 1 files changed, 3 insertions(+), 57 deletions(-)

diff --git a/src/msg.cpp b/src/msg.cpp
index 9883246..f180d67 100644
--- a/src/msg.cpp
+++ b/src/msg.cpp
@@ -16,63 +16,9 @@
  * =====================================================================================
  */
 #include "msg.h"
+#include "bh_util.h"
 
-namespace bhome_shm {
-	
-
-bool MsgMetaV1::Parse(const void *p)
+namespace bhome_msg
 {
-    assert(p);
-    *this = *static_cast<const MsgMetaV1*>(p);
-    return tag_ == kMsgMetaTag;
-}
 
-void MsgMetaV1::Pack(void *p)
-{
-    *static_cast<MsgMetaV1*>(p) = *this;
-}
-
-bool Msg::Build(SharedMemory &shm, const MQId &src_id, const void *data, const size_t size, const bool refcount)
-{
-    if (!data || !size) {
-        return false;
-    }
-    void *p = shm.Alloc(sizeof(MsgMetaV1) + size);
-    if (!p) {
-        return false;
-    }
-    RefCount *rc = 0;
-    if (refcount) {
-        rc = shm.New<RefCount>();
-        if (!rc) {
-            shm.Dealloc(p);
-            return false;
-        }
-    }
-    MsgMetaV1 meta;
-    meta.data_size_ = size;
-    meta.src_id_ = src_id;
-    meta.Pack(p);
-    memcpy(static_cast<char *>(p) + sizeof(meta), data, size);
-    Msg(p, rc).swap(*this);
-    return true;
-
-}
-
-int Msg::Release(SharedMemory &shm) 
-{
-    if (IsCounted()) {
-        const int n = count_->Dec();
-        if (n != 0) {
-            return n;
-        }
-    }
-    // free data
-    shm.Dealloc(ptr_);
-    ptr_ = 0;
-    shm.Delete(count_);
-    count_ = 0;
-    return 0;
-}
-
-} // namespace bhome_shm
+} // namespace bhome_msg

--
Gitblit v1.8.0