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 | 71 +++--------------------------------
1 files changed, 7 insertions(+), 64 deletions(-)
diff --git a/src/shm_queue.h b/src/shm_queue.h
index 0041f16..952dae9 100644
--- a/src/shm_queue.h
+++ b/src/shm_queue.h
@@ -28,77 +28,20 @@
namespace bhome_shm
{
-template <class D>
-using Circular = boost::circular_buffer<D, Allocator<D>>;
-// using Circular = robust::CircularBuffer<D, Allocator<D>>;
-
-template <class D>
-class SharedQueue
-{
-public:
- SharedQueue(const uint32_t len, Allocator<D> const &alloc) :
- queue_(len, alloc) {}
-
- 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)
- {
- if (!queue_.empty()) {
- d = queue_.front();
- queue_.pop_front();
- return true;
- } else {
- return false;
- }
- }
- bool TryWrite(const D &d)
- {
- if (!queue_.full()) {
- queue_.push_back(d);
- return true;
- } else {
- return false;
- }
- }
-
-private:
- Circular<D> queue_;
-};
-
-template <int Power = 4>
+// just wrap robust::AtomicQ63
class SharedQ63
{
public:
- 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();
- }
- } while (steady_clock::now() < end_time);
- return false;
- }
+ template <class... T>
+ explicit SharedQ63(T &&...t) {} // easy testing
+
+ 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:
- robust::AtomicQueue<Power, Data> queue_;
+ AQ63 queue_;
};
} // namespace bhome_shm
--
Gitblit v1.8.0