Move MultiTimeout to MultiTimeout.h.
This commit is contained in:
parent
aeed6c45d7
commit
8537b3d495
@ -39,7 +39,7 @@
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
#include "td/actor/MultiPromise.h"
|
||||
#include "td/actor/Timeout.h"
|
||||
#include "td/actor/MultiTimeout.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/FlatHashMap.h"
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include "td/telegram/UserId.h"
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
#include "td/actor/Timeout.h"
|
||||
#include "td/actor/MultiTimeout.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/FlatHashMap.h"
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
#include "td/actor/MultiPromise.h"
|
||||
#include "td/actor/Timeout.h"
|
||||
#include "td/actor/MultiTimeout.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/FlatHashMap.h"
|
||||
|
@ -61,6 +61,7 @@
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
#include "td/actor/MultiPromise.h"
|
||||
#include "td/actor/MultiTimeout.h"
|
||||
#include "td/actor/SignalSlot.h"
|
||||
#include "td/actor/Timeout.h"
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "td/telegram/td_api.h"
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
#include "td/actor/Timeout.h"
|
||||
#include "td/actor/MultiTimeout.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/FlatHashMap.h"
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include "td/telegram/telegram_api.h"
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
#include "td/actor/Timeout.h"
|
||||
#include "td/actor/MultiTimeout.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/FlatHashMap.h"
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include "td/telegram/UserId.h"
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
#include "td/actor/Timeout.h"
|
||||
#include "td/actor/MultiTimeout.h"
|
||||
|
||||
#include "td/utils/buffer.h"
|
||||
#include "td/utils/common.h"
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "td/telegram/telegram_api.h"
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
#include "td/actor/Timeout.h"
|
||||
#include "td/actor/MultiTimeout.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/FlatHashMap.h"
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "td/db/DbKey.h"
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
#include "td/actor/Timeout.h"
|
||||
#include "td/actor/MultiTimeout.h"
|
||||
|
||||
#include "td/utils/buffer.h"
|
||||
#include "td/utils/common.h"
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include "td/telegram/telegram_api.h"
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
#include "td/actor/Timeout.h"
|
||||
#include "td/actor/MultiTimeout.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/FlatHashMap.h"
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include "td/telegram/WebPageId.h"
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
#include "td/actor/Timeout.h"
|
||||
#include "td/actor/MultiTimeout.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/FlatHashMap.h"
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
81
tdactor/td/actor/MultiTimeout.h
Normal file
81
tdactor/td/actor/MultiTimeout.h
Normal file
@ -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
|
@ -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
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user