From 4ad4f24f18cf7d0af22ca885baebc6a3eb37e7d0 Mon Sep 17 00:00:00 2001
From: lichao <lichao@aiotlink.com>
Date: 星期四, 20 五月 2021 10:08:40 +0800
Subject: [PATCH] rename socket.h/cpp to shm_socket.h/cpp.

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

diff --git a/src/shm_queue.h b/src/shm_queue.h
index 0041f16..7871fe0 100644
--- a/src/shm_queue.h
+++ b/src/shm_queue.h
@@ -30,7 +30,6 @@
 
 template <class D>
 using Circular = boost::circular_buffer<D, Allocator<D>>;
-// using Circular = robust::CircularBuffer<D, Allocator<D>>;
 
 template <class D>
 class SharedQueue
@@ -54,6 +53,7 @@
 	}
 	bool TryRead(D &d)
 	{
+		// bhome_shm::Guard lock(mutex_);
 		if (!queue_.empty()) {
 			d = queue_.front();
 			queue_.pop_front();
@@ -64,6 +64,7 @@
 	}
 	bool TryWrite(const D &d)
 	{
+		// bhome_shm::Guard lock(mutex_);
 		if (!queue_.full()) {
 			queue_.push_back(d);
 			return true;
@@ -74,23 +75,28 @@
 
 private:
 	Circular<D> queue_;
+	// bhome_shm::Mutex mutex_;
 };
 
 template <int Power = 4>
 class SharedQ63
 {
 public:
+	template <class... T>
+	explicit SharedQ63(T &&...t) {} // easy testing
+
 	typedef int64_t Data;
 	bool Read(Data &d, const int timeout_ms)
 	{
 		using namespace std::chrono;
 		auto end_time = steady_clock::now() + milliseconds(timeout_ms);
 		do {
-			if (TryRead(d)) {
-				return true;
-			} else {
-				robust::QuickSleep();
+			for (int i = 0; i < 100; ++i) {
+				if (TryRead(d)) {
+					return true;
+				}
 			}
+			robust::QuickSleep();
 		} while (steady_clock::now() < end_time);
 		return false;
 	}

--
Gitblit v1.8.0