From d33a69463f1a75134d01191be0b9e1bdd757dd4b Mon Sep 17 00:00:00 2001
From: lichao <lichao@aiotlink.com>
Date: 星期五, 30 四月 2021 15:27:59 +0800
Subject: [PATCH] add atomic queue, no lock, unorder.

---
 src/shm_msg_queue.cpp |   15 +++++++--------
 1 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/shm_msg_queue.cpp b/src/shm_msg_queue.cpp
index ae019bf..03a6cfb 100644
--- a/src/shm_msg_queue.cpp
+++ b/src/shm_msg_queue.cpp
@@ -84,19 +84,18 @@
 	return Shmq::Find(shm, MsgQIdToName(remote_id));
 }
 
-bool ShmMsgQueue::TrySend(SharedMemory &shm, const MQId remote_id, const MsgI &msg, OnSend const &onsend)
+bool ShmMsgQueue::TrySend(SharedMemory &shm, const MQId remote_id, MsgI msg)
 {
 	Queue *remote = Find(shm, remote_id);
+	bool r = false;
 	if (remote) {
-		if (onsend) {
-			return remote->TryWrite(msg, [&onsend](const MsgI &msg) { onsend(); msg.AddRef(); });
-		} else {
-			return remote->TryWrite(msg, [](const MsgI &msg) { msg.AddRef(); });
+		msg.AddRef();
+		r = remote->TryWrite(msg);
+		if (!r) {
+			msg.Release();
 		}
-	} else {
-		// SetLestError(eNotFound);
-		return false;
 	}
+	return r;
 }
 
 // Test shows that in the 2 cases:

--
Gitblit v1.8.0