From 921417f41dff1c3ac754babaa69d3b855c94af41 Mon Sep 17 00:00:00 2001
From: lichao <lichao@aiotlink.com>
Date: 星期五, 26 三月 2021 11:57:49 +0800
Subject: [PATCH] remove utest program
---
src/shm_queue.h | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/shm_queue.h b/src/shm_queue.h
index a98fcf4..14f43c0 100644
--- a/src/shm_queue.h
+++ b/src/shm_queue.h
@@ -53,9 +53,11 @@
using Super::size;
using Super::capacity;
const MQId &Id() const { return id_; }
- bool Write(D buf, const int timeout_ms) {
+ template <class OnWrite>
+ bool Write(const D &buf, const int timeout_ms, const OnWrite &onWrite) {
Guard lock(mutex());
if (cond_write_.timed_wait(lock, MSFromNow(timeout_ms), [&]() { return !this->full(); })) {
+ onWrite();
this->push_back(buf);
cond_read_.notify_one();
return true;
@@ -63,11 +65,13 @@
return false;
}
}
+ bool Write(const D &buf, const int timeout_ms) { return Write(buf, timeout_ms, [](){}); }
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;
@@ -90,6 +94,8 @@
bool Send(const MQId &remote_id, const void *data, const size_t size, const int timeout_ms);
bool Recv(MQId &source_id, void *&data, size_t &size, const int timeout_ms);
const MQId &Id() const { return data()->Id(); }
+ bool Send(const MQId &remote_id, const Msg &msg, const int timeout_ms);
+ bool Recv(Msg &msg, const int timeout_ms) { return Read(msg, timeout_ms); }
};
} // namespace bhome_shm
--
Gitblit v1.8.0