Add non-template Scheduler::destroy_on_scheduler_impl.

This commit is contained in:
levlam 2022-07-20 13:57:05 +03:00
parent 0f87447ffc
commit 51513f1780
3 changed files with 21 additions and 17 deletions

View File

@ -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);

View File

@ -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();

View File

@ -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) {