From e730d57cd0bdd446c0f1ee6cdae4a69f85ad1c71 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Wed, 1 May 2024 07:54:36 +0000 Subject: [PATCH] feat support build thread deleter with timer --- src/sled/timer/timer.cc | 14 ++++++++------ src/sled/timer/timer.h | 3 ++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/sled/timer/timer.cc b/src/sled/timer/timer.cc index 39b5174..1af7fae 100644 --- a/src/sled/timer/timer.cc +++ b/src/sled/timer/timer.cc @@ -109,21 +109,23 @@ Timer::Trigger(TimerGeneration generation) } } -std::unique_ptr -TimerManager::CreateTimer(const std::string &name, Timer::OnExpired on_expired) +std::unique_ptr +TimerManager::CreateTimer(const std::string &name, Timer::OnExpired on_expired, TaskQueueBase *owner) { next_id_ = TimerID(next_id_ + 1); TimerID id = next_id_; std::unique_ptr timeout = timeout_creator_(sled::TaskQueueBase::DelayPrecision::kHigh); - auto timer = std::unique_ptr(new Timer( + auto timer = new Timer( id, name, std::move(on_expired), /* ungrgister_handler=*/[this, id]() { timers_.erase(id); }, - std::move(timeout))); - timers_[id] = timer.get(); - return timer; + std::move(timeout)); + auto unique_timer = std::unique_ptr(timer, TimerThreadDeleter(owner)); + + timers_[id] = unique_timer.get(); + return unique_timer; } void diff --git a/src/sled/timer/timer.h b/src/sled/timer/timer.h index 9108f36..dfde01d 100644 --- a/src/sled/timer/timer.h +++ b/src/sled/timer/timer.h @@ -73,7 +73,8 @@ class TimerManager { public: explicit TimerManager(TimeoutCreator timeout_creator) : timeout_creator_(timeout_creator) {} - std::unique_ptr CreateTimer(const std::string &name, Timer::OnExpired on_expired); + std::unique_ptr + CreateTimer(const std::string &name, Timer::OnExpired on_expired, TaskQueueBase *owner = nullptr); void HandleTimeout(TimeoutID timeout_id); private: