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/sendq.cpp |   26 +++++++++++++-------------
 1 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/src/sendq.cpp b/src/sendq.cpp
index 4be24f1..c0d5afd 100644
--- a/src/sendq.cpp
+++ b/src/sendq.cpp
@@ -16,10 +16,12 @@
  * =====================================================================================
  */
 #include "sendq.h"
-#include "shm_queue.h"
+#include "shm_msg_queue.h"
 #include <chrono>
 
-int SendQ::DoSend1Remote(bhome_shm::ShmMsgQueue &mq, const Remote &remote, Array &arr)
+using namespace bhome_shm;
+
+int SendQ::DoSend1Remote(ShmMsgQueue &mq, const Remote remote, Array &arr)
 {
 	auto FirstNotExpired = [](Array &l) {
 		auto Less = [](const TimedMsg &msg, const TimePoint &tp) { return msg.expire() < tp; };
@@ -33,7 +35,7 @@
 			info.on_expire_(info.data_);
 		}
 		if (info.data_.index() == 0) {
-			boost::variant2::get<0>(info.data_).Release(mq.shm());
+			boost::variant2::get<0>(info.data_).Release();
 		}
 	}
 
@@ -41,18 +43,16 @@
 		bool r = false;
 		if (d.index() == 0) {
 			auto &msg = boost::variant2::get<0>(pos->data().data_);
-			r = mq.TrySend(*(MQId *) remote.data(), msg);
-			if (r && msg.IsCounted()) {
-				msg.Release(mq.shm());
+			r = mq.TrySend(remote, msg);
+			if (r) {
+				msg.Release();
 			}
 		} else {
 			auto &content = boost::variant2::get<1>(pos->data().data_);
 			MsgI msg;
-			if (msg.Make(mq.shm(), content)) {
-				r = mq.TrySend(*(MQId *) remote.data(), msg);
-				if (!r || msg.IsCounted()) {
-					msg.Release(mq.shm());
-				}
+			if (msg.Make(content)) {
+				DEFER1(msg.Release(););
+				r = mq.TrySend(remote, msg);
 			}
 		}
 		return r;
@@ -67,7 +67,7 @@
 	return nprocessed;
 }
 
-int SendQ::DoSend1Remote(bhome_shm::ShmMsgQueue &mq, const Remote &remote, ArrayList &al)
+int SendQ::DoSend1Remote(ShmMsgQueue &mq, const Remote remote, ArrayList &al)
 {
 	int nsend = 0;
 	auto AllSent = [&](Array &arr) {
@@ -78,7 +78,7 @@
 	return nsend;
 }
 
-bool SendQ::TrySend(bhome_shm::ShmMsgQueue &mq)
+bool SendQ::TrySend(ShmMsgQueue &mq)
 {
 	std::unique_lock<std::mutex> lock(mutex_out_);
 	size_t nsend = 0;

--
Gitblit v1.8.0