From 330f78f3334bcdcdb4cc2ab2dbf66604e0224d71 Mon Sep 17 00:00:00 2001
From: lichao <lichao@aiotlink.com>
Date: 星期五, 21 五月 2021 16:21:45 +0800
Subject: [PATCH] Merge branch 'master' of http://192.168.5.5:10010/r/valib/bhshmq
---
src/timed_queue.h | 39 +++++++++++++++++++++++++++------------
1 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/src/timed_queue.h b/src/timed_queue.h
index 14e318d..af77b11 100644
--- a/src/timed_queue.h
+++ b/src/timed_queue.h
@@ -1,7 +1,7 @@
/*
* =====================================================================================
*
- * Filename: failed_msg.h
+ * Filename: timed_queue.h
*
* Description:
*
@@ -24,23 +24,38 @@
#include <string>
template <class Data, class ClockType = std::chrono::steady_clock>
-class TimedQueue
+class TimedData
{
public:
typedef ClockType Clock;
typedef typename Clock::time_point TimePoint;
typedef typename Clock::duration Duration;
+ TimedData(const TimePoint &expire, const Data &data) :
+ expire_(expire), data_(data) {}
+ TimedData(const TimePoint &expire, Data &&data) :
+ expire_(expire), data_(std::move(data)) {}
+ bool Expired() const { return Clock::now() > expire_; }
+ const TimePoint &expire() const { return expire_; }
+ Data &data() { return data_; }
+ Data const &data() const { return data_; }
+
private:
- struct Record {
- TimePoint expire_;
- Data data_;
- Record(const TimePoint &expire, const Data &data) :
- expire_(expire), data_(data) {}
- Record(const TimePoint &expire, Data &&data) :
- expire_(expire), data_(std::move(data)) {}
- bool Expired() { return Clock::now() > expire_; }
- };
+ TimePoint expire_;
+ Data data_;
+};
+
+template <class Data, class ClockType = std::chrono::steady_clock>
+class TimedQueue
+{
+ typedef TimedData<Data, ClockType> Record;
+
+public:
+ typedef typename Record::Clock Clock;
+ typedef typename Record::TimePoint TimePoint;
+ typedef typename Record::Duration Duration;
+
+private:
typedef std::list<Record> Queue;
Synced<Queue> queue_;
@@ -62,7 +77,7 @@
do {
if (it->Expired()) {
it = q.erase(it);
- } else if (func(it->data_)) {
+ } else if (func(it->data())) {
it = q.erase(it);
} else {
++it;
--
Gitblit v1.8.0