From c095be83aa9d795023a54ddaccfb6717258561c9 Mon Sep 17 00:00:00 2001
From: lichao <lichao@aiotlink.com>
Date: 星期一, 29 三月 2021 11:37:20 +0800
Subject: [PATCH] read/write multiple msgs; move mqid.

---
 src/msg.cpp |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/src/msg.cpp b/src/msg.cpp
index 4ddb726..9883246 100644
--- a/src/msg.cpp
+++ b/src/msg.cpp
@@ -59,9 +59,20 @@
 
 }
 
-void Msg::FreeFrom(SharedMemory &shm)
+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

--
Gitblit v1.8.0