From d3e7f93e69cb24c766292d8780e745caf24d42a8 Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期四, 25 三月 2021 18:30:51 +0800 Subject: [PATCH] add ref count. --- src/shm_queue.cpp | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/shm_queue.cpp b/src/shm_queue.cpp index f770afc..77add97 100644 --- a/src/shm_queue.cpp +++ b/src/shm_queue.cpp @@ -73,7 +73,9 @@ if (Send(remote_id, msg, timeout_ms)) { return true; } else { - msg.FreeFrom(shm()); + if (msg.RemoveRef() == 0) { // works for both refcounted and not counted. + msg.FreeFrom(shm()); + } } } return false; @@ -83,9 +85,10 @@ { Msg msg; if (Read(msg, timeout_ms)) { + DEFER1(if (msg.RemoveRef() == 0) { msg.FreeFrom(shm()); }); + auto ptr = msg.get<char>(); if (ptr) { - DEFER1(shm().Dealloc(ptr);); MsgMetaV1 meta; meta.Parse(ptr); source_id = meta.src_id_; -- Gitblit v1.8.0