aboutsummaryrefslogtreecommitdiffhomepage
path: root/tdactor/td
diff options
context:
space:
mode:
authorlevlam <levlam@telegram.org>2022-07-20 13:57:05 +0300
committerlevlam <levlam@telegram.org>2022-07-20 13:57:05 +0300
commit51513f1780241f63faede6844b1a80e2d26dd540 (patch)
tree3a27d4806852f5cc12acc2981d399d2fc1e54fdf /tdactor/td
parent0f87447ffcdabca63f572ece90d1fcfd91e3445b (diff)
Add non-template Scheduler::destroy_on_scheduler_impl.
Diffstat (limited to 'tdactor/td')
-rw-r--r--tdactor/td/actor/impl/Scheduler-decl.h2
-rw-r--r--tdactor/td/actor/impl/Scheduler.cpp15
-rw-r--r--tdactor/td/actor/impl/Scheduler.h21
3 files changed, 21 insertions, 17 deletions
diff --git a/tdactor/td/actor/impl/Scheduler-decl.h b/tdactor/td/actor/impl/Scheduler-decl.h
index 6980ac609..57f49dbb4 100644
--- a/tdactor/td/actor/impl/Scheduler-decl.h
+++ b/tdactor/td/actor/impl/Scheduler-decl.h
@@ -153,6 +153,8 @@ class Scheduler {
private:
static void set_scheduler(Scheduler *scheduler);
+ void destroy_on_scheduler_impl(int32 sched_id, Promise<Unit> action);
+
class ServiceActor final : public Actor {
public:
void set_queue(std::shared_ptr<MpscPollableQueue<EventFull>> queues);
diff --git a/tdactor/td/actor/impl/Scheduler.cpp b/tdactor/td/actor/impl/Scheduler.cpp
index b29b5b34d..9edcaff40 100644
--- a/tdactor/td/actor/impl/Scheduler.cpp
+++ b/tdactor/td/actor/impl/Scheduler.cpp
@@ -362,6 +362,21 @@ void Scheduler::run_on_scheduler(int32 sched_id, Promise<Unit> action) {
action.set_value(Unit());
}
+void Scheduler::destroy_on_scheduler_impl(int32 sched_id, Promise<Unit> action) {
+ 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, std::move(action));
+
+ context_ = current_context;
+ LOG_TAG = current_tag;
+}
+
void Scheduler::add_to_mailbox(ActorInfo *actor_info, Event &&event) {
if (!actor_info->is_running()) {
auto node = actor_info->get_list_node();
diff --git a/tdactor/td/actor/impl/Scheduler.h b/tdactor/td/actor/impl/Scheduler.h
index 8ead97efe..182066145 100644
--- a/tdactor/td/actor/impl/Scheduler.h
+++ b/tdactor/td/actor/impl/Scheduler.h
@@ -172,24 +172,11 @@ inline void Scheduler::send_to_scheduler(int32 sched_id, const ActorId<Actor> &a
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;
+ if (!value.empty()) {
+ destroy_on_scheduler_impl(sched_id, PromiseCreator::lambda([value = std::move(value)](Unit) {
+ // destroy value
+ }));
}
-
- 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) {