From 68c7bef33e74f23aa0136ccd6f7faa654d671ebc Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期五, 21 五月 2021 09:23:01 +0800 Subject: [PATCH] center publish notify; fix topic partial match. --- src/shm_queue.h | 17 +++++++++++------ 1 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/shm_queue.h b/src/shm_queue.h index 0041f16..3a2cea6 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 @@ -47,13 +46,14 @@ if (TryRead(d)) { return true; } else { - robust::QuickSleep(); + std::this_thread::sleep_for(1ms); } } while (steady_clock::now() < end_time); return false; } 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; @@ -80,17 +81,21 @@ 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; + } } + std::this_thread::sleep_for(1ms); } while (steady_clock::now() < end_time); return false; } -- Gitblit v1.8.0