From 056f71f24cefaf88f2a93714c6678c03ed5f1e0e Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期五, 02 七月 2021 16:54:33 +0800
Subject: [PATCH] fixed to adapt gcc-5.4 & glibc-2.25
---
src/shm_queue.h | 35 +++++++++++------------------------
1 files changed, 11 insertions(+), 24 deletions(-)
diff --git a/src/shm_queue.h b/src/shm_queue.h
index 7e4ec31..952dae9 100644
--- a/src/shm_queue.h
+++ b/src/shm_queue.h
@@ -19,42 +19,29 @@
#ifndef SHM_QUEUE_JE0OEUP3
#define SHM_QUEUE_JE0OEUP3
+#include "robust.h"
#include "shm.h"
#include <atomic>
+#include <boost/circular_buffer.hpp>
#include <chrono>
namespace bhome_shm
{
-template <class D>
-using Circular = robust::CircularBuffer<D, Allocator<D>>;
-
-template <class D>
-class SharedQueue
+// just wrap robust::AtomicQ63
+class SharedQ63
{
public:
- SharedQueue(const uint32_t len, Allocator<D> const &alloc) :
- queue_(len, alloc) {}
+ template <class... T>
+ explicit SharedQ63(T &&...t) {} // easy testing
- bool Read(D &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();
- }
- } while (steady_clock::now() < end_time);
- return false;
- }
- bool TryRead(D &d) { return queue_.pop_front(d); }
- bool TryWrite(const D &d) { return queue_.push_back(d); }
+ typedef robust::AtomicQ63 AQ63;
+ typedef AQ63::Data Data;
+ bool TryRead(Data &d, const bool try_more = true) { return queue_.pop(d, try_more); }
+ bool TryWrite(const Data d, const bool try_more = true) { return queue_.push(d, try_more); }
private:
- typedef Circular<D> Queue;
- Queue queue_;
+ AQ63 queue_;
};
} // namespace bhome_shm
--
Gitblit v1.8.0