aboutsummaryrefslogtreecommitdiffhomepage
path: root/tdactor
diff options
context:
space:
mode:
authorlevlam <levlam@telegram.org>2022-07-02 23:32:18 +0300
committerlevlam <levlam@telegram.org>2022-07-02 23:32:18 +0300
commit8537b3d4956801936011c4f02b34137b60713eac (patch)
tree6fe5931de5d2338f3b99609fe5697c0cdc762f4c /tdactor
parentaeed6c45d727e3e4ea3a88eaf161d1d2203ffc17 (diff)
Move MultiTimeout to MultiTimeout.h.
Diffstat (limited to 'tdactor')
-rw-r--r--tdactor/CMakeLists.txt3
-rw-r--r--tdactor/td/actor/MultiTimeout.cpp (renamed from tdactor/td/actor/Timeout.cpp)3
-rw-r--r--tdactor/td/actor/MultiTimeout.h81
-rw-r--r--tdactor/td/actor/Timeout.h68
-rw-r--r--tdactor/test/actors_bugs.cpp2
5 files changed, 85 insertions, 72 deletions
diff --git a/tdactor/CMakeLists.txt b/tdactor/CMakeLists.txt
index c20af79cd..a156384ce 100644
--- a/tdactor/CMakeLists.txt
+++ b/tdactor/CMakeLists.txt
@@ -11,7 +11,7 @@ set(TDACTOR_SOURCE
td/actor/ConcurrentScheduler.cpp
td/actor/impl/Scheduler.cpp
td/actor/MultiPromise.cpp
- td/actor/Timeout.cpp
+ td/actor/MultiTimeout.cpp
td/actor/actor.h
td/actor/ConcurrentScheduler.h
@@ -27,6 +27,7 @@ set(TDACTOR_SOURCE
td/actor/impl/Scheduler-decl.h
td/actor/impl/Scheduler.h
td/actor/MultiPromise.h
+ td/actor/MultiTimeout.h
td/actor/PromiseFuture.h
td/actor/SchedulerLocalStorage.h
td/actor/SignalSlot.h
diff --git a/tdactor/td/actor/Timeout.cpp b/tdactor/td/actor/MultiTimeout.cpp
index a3b191ab6..8c3dcb942 100644
--- a/tdactor/td/actor/Timeout.cpp
+++ b/tdactor/td/actor/MultiTimeout.cpp
@@ -4,10 +4,9 @@
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
-#include "td/actor/Timeout.h"
+#include "td/actor/MultiTimeout.h"
#include "td/utils/logging.h"
-#include "td/utils/Time.h"
namespace td {
diff --git a/tdactor/td/actor/MultiTimeout.h b/tdactor/td/actor/MultiTimeout.h
new file mode 100644
index 000000000..64803d346
--- /dev/null
+++ b/tdactor/td/actor/MultiTimeout.h
@@ -0,0 +1,81 @@
+//
+// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+#pragma once
+
+#include "td/actor/actor.h"
+
+#include "td/utils/common.h"
+#include "td/utils/Heap.h"
+#include "td/utils/Slice.h"
+#include "td/utils/Time.h"
+
+#include <set>
+
+namespace td {
+
+// TODO optimize
+class MultiTimeout final : public Actor {
+ struct Item final : public HeapNode {
+ int64 key;
+
+ explicit Item(int64 key) : key(key) {
+ }
+
+ bool operator<(const Item &other) const {
+ return key < other.key;
+ }
+ };
+
+ public:
+ using Data = void *;
+ using Callback = void (*)(Data, int64);
+ explicit MultiTimeout(Slice name) {
+ register_actor(name, this).release();
+ }
+
+ void set_callback(Callback callback) {
+ callback_ = callback;
+ }
+ void set_callback_data(Data data) {
+ data_ = data;
+ }
+
+ bool has_timeout(int64 key) const;
+
+ void set_timeout_in(int64 key, double timeout) {
+ set_timeout_at(key, Time::now() + timeout);
+ }
+
+ void add_timeout_in(int64 key, double timeout) {
+ add_timeout_at(key, Time::now() + timeout);
+ }
+
+ void set_timeout_at(int64 key, double timeout);
+
+ void add_timeout_at(int64 key, double timeout); // memcache semantics, doesn't replace old timeout
+
+ void cancel_timeout(int64 key);
+
+ void run_all();
+
+ private:
+ friend class Scheduler;
+
+ Callback callback_;
+ Data data_;
+
+ KHeap<double> timeout_queue_;
+ std::set<Item> items_;
+
+ void update_timeout();
+
+ void timeout_expired() final;
+
+ vector<int64> get_expired_keys(double now);
+};
+
+} // namespace td
diff --git a/tdactor/td/actor/Timeout.h b/tdactor/td/actor/Timeout.h
index c5779808c..5c2293b99 100644
--- a/tdactor/td/actor/Timeout.h
+++ b/tdactor/td/actor/Timeout.h
@@ -8,13 +8,6 @@
#include "td/actor/actor.h"
-#include "td/utils/common.h"
-#include "td/utils/Heap.h"
-#include "td/utils/Slice.h"
-#include "td/utils/Time.h"
-
-#include <set>
-
namespace td {
class Timeout final : public Actor {
@@ -70,65 +63,4 @@ class Timeout final : public Actor {
}
};
-// TODO optimize
-class MultiTimeout final : public Actor {
- struct Item final : public HeapNode {
- int64 key;
-
- explicit Item(int64 key) : key(key) {
- }
-
- bool operator<(const Item &other) const {
- return key < other.key;
- }
- };
-
- public:
- using Data = void *;
- using Callback = void (*)(Data, int64);
- explicit MultiTimeout(Slice name) {
- register_actor(name, this).release();
- }
-
- void set_callback(Callback callback) {
- callback_ = callback;
- }
- void set_callback_data(Data data) {
- data_ = data;
- }
-
- bool has_timeout(int64 key) const;
-
- void set_timeout_in(int64 key, double timeout) {
- set_timeout_at(key, Time::now() + timeout);
- }
-
- void add_timeout_in(int64 key, double timeout) {
- add_timeout_at(key, Time::now() + timeout);
- }
-
- void set_timeout_at(int64 key, double timeout);
-
- void add_timeout_at(int64 key, double timeout); // memcache semantics, doesn't replace old timeout
-
- void cancel_timeout(int64 key);
-
- void run_all();
-
- private:
- friend class Scheduler;
-
- Callback callback_;
- Data data_;
-
- KHeap<double> timeout_queue_;
- std::set<Item> items_;
-
- void update_timeout();
-
- void timeout_expired() final;
-
- vector<int64> get_expired_keys(double now);
-};
-
} // namespace td
diff --git a/tdactor/test/actors_bugs.cpp b/tdactor/test/actors_bugs.cpp
index c90ab371a..9f3841430 100644
--- a/tdactor/test/actors_bugs.cpp
+++ b/tdactor/test/actors_bugs.cpp
@@ -6,7 +6,7 @@
//
#include "td/actor/actor.h"
#include "td/actor/ConcurrentScheduler.h"
-#include "td/actor/Timeout.h"
+#include "td/actor/MultiTimeout.h"
#include "td/utils/common.h"
#include "td/utils/logging.h"