From cab831748a2a9cc18b7f18f3b5e14a4374b7ab68 Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期一, 17 五月 2021 18:34:26 +0800 Subject: [PATCH] socket send using abs addr, avoid shm find by id. --- src/shm_queue.h | 15 +++++++++++---- 1 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/shm_queue.h b/src/shm_queue.h index 0041f16..5c9e077 100644 --- a/src/shm_queue.h +++ b/src/shm_queue.h @@ -54,6 +54,7 @@ } bool TryRead(D &d) { + // bhome_shm::Guard lock(mutex_); if (!queue_.empty()) { d = queue_.front(); queue_.pop_front(); @@ -64,6 +65,7 @@ } bool TryWrite(const D &d) { + // bhome_shm::Guard lock(mutex_); if (!queue_.full()) { queue_.push_back(d); return true; @@ -74,23 +76,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