From 3f4f049ac015c695a965142e7b1180eae83ae781 Mon Sep 17 00:00:00 2001
From: lichao <lichao@aiotlink.com>
Date: 星期四, 25 三月 2021 16:18:26 +0800
Subject: [PATCH] reason for speed change; refactor.

---
 src/shm_queue.h |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/shm_queue.h b/src/shm_queue.h
index d0eb972..023b2d1 100644
--- a/src/shm_queue.h
+++ b/src/shm_queue.h
@@ -53,7 +53,7 @@
     using Super::size;
     using Super::capacity;
     const MQId &Id() const { return id_; }
-    bool Write(D buf, const int timeout_ms) {
+    bool Write(const D &buf, const int timeout_ms) {
         Guard lock(mutex());
         if (cond_write_.timed_wait(lock, MSFromNow(timeout_ms), [&]() { return !this->full(); })) {
             this->push_back(buf);
@@ -67,7 +67,8 @@
     bool Read(D &buf, const int timeout_ms){
         Guard lock(mutex());
         if (cond_read_.timed_wait(lock, MSFromNow(timeout_ms), [&]() { return !this->empty(); })) {
-            buf = this->front();
+            using std::swap;
+            swap(buf, this->front());
             this->pop_front();
             cond_write_.notify_one();
             return true;

--
Gitblit v1.8.0