aboutsummaryrefslogtreecommitdiffhomepage
path: root/tdactor
diff options
context:
space:
mode:
authorlevlam <levlam@telegram.org>2022-07-20 13:40:14 +0300
committerlevlam <levlam@telegram.org>2022-07-20 13:40:14 +0300
commit0f87447ffcdabca63f572ece90d1fcfd91e3445b (patch)
tree22d5b5959bd9ddac5ef1be34845526b50d7af4b6 /tdactor
parentac8af37872a4551a3960bfc4a48d1d6e351e0bff (diff)
Asynchronously destroy some big data storages.
Diffstat (limited to 'tdactor')
-rw-r--r--tdactor/td/actor/impl/Scheduler-decl.h3
-rw-r--r--tdactor/td/actor/impl/Scheduler.h24
2 files changed, 26 insertions, 1 deletions
diff --git a/tdactor/td/actor/impl/Scheduler-decl.h b/tdactor/td/actor/impl/Scheduler-decl.h
index 72893e4e8..6980ac609 100644
--- a/tdactor/td/actor/impl/Scheduler-decl.h
+++ b/tdactor/td/actor/impl/Scheduler-decl.h
@@ -102,6 +102,9 @@ class Scheduler {
void run_on_scheduler(int32 sched_id, Promise<Unit> action); // TODO Action
+ template <class T>
+ void destroy_on_scheduler(int32 sched_id, T &value);
+
template <ActorSendType send_type, class EventT>
void send_lambda(ActorRef actor_ref, EventT &&lambda);
diff --git a/tdactor/td/actor/impl/Scheduler.h b/tdactor/td/actor/impl/Scheduler.h
index 3cdae11fe..8ead97efe 100644
--- a/tdactor/td/actor/impl/Scheduler.h
+++ b/tdactor/td/actor/impl/Scheduler.h
@@ -161,7 +161,7 @@ void Scheduler::flush_mailbox(ActorInfo *actor_info, const RunFuncT &run_func, c
mailbox.erase(mailbox.begin(), mailbox.begin() + i);
}
-inline void Scheduler::send_to_scheduler(int32 sched_id, const ActorId<> &actor_id, Event &&event) {
+inline void Scheduler::send_to_scheduler(int32 sched_id, const ActorId<Actor> &actor_id, Event &&event) {
if (sched_id == sched_id_) {
ActorInfo *actor_info = actor_id.get_actor_info();
pending_events_[actor_info].push_back(std::move(event));
@@ -170,6 +170,28 @@ inline void Scheduler::send_to_scheduler(int32 sched_id, const ActorId<> &actor_
}
}
+template <class T>
+inline void Scheduler::destroy_on_scheduler(int32 sched_id, T &value) {
+ if (sched_id < 0 || sched_id_ == sched_id || value.empty()) {
+ return;
+ }
+
+ auto empty_context = std::make_shared<ActorContext>();
+ empty_context->this_ptr_ = empty_context;
+ ActorContext *current_context = context_;
+ context_ = empty_context.get();
+
+ const char *current_tag = LOG_TAG;
+ LOG_TAG = nullptr;
+
+ run_on_scheduler(sched_id, PromiseCreator::lambda([value = std::move(value)](Unit) {
+ // destroy value
+ }));
+
+ context_ = current_context;
+ LOG_TAG = current_tag;
+}
+
inline void Scheduler::before_tail_send(const ActorId<> &actor_id) {
// TODO
}