From 3b93dc0dc34008cf25b2b12f6b026b3d9e4ed623 Mon Sep 17 00:00:00 2001
From: lichao <lichao@aiotlink.com>
Date: 星期五, 30 四月 2021 12:48:14 +0800
Subject: [PATCH] guard shm alloc; rm OnWrite,dup lock in shm queue.

---
 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