feat support build thread deleter with timer
Some checks failed
linux-x64-gcc / linux-gcc (Debug) (push) Has been cancelled
linux-arm-gcc / linux-gcc-armhf (push) Has been cancelled
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (push) Has been cancelled
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Has been cancelled
linux-x64-gcc / linux-gcc (Release) (push) Has been cancelled
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Has been cancelled

This commit is contained in:
tqcq 2024-05-01 07:54:36 +00:00
parent 216a5c1d99
commit e730d57cd0
2 changed files with 10 additions and 7 deletions

View File

@ -109,21 +109,23 @@ Timer::Trigger(TimerGeneration generation)
}
}
std::unique_ptr<Timer>
TimerManager::CreateTimer(const std::string &name, Timer::OnExpired on_expired)
std::unique_ptr<Timer, TimerThreadDeleter>
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 = timeout_creator_(sled::TaskQueueBase::DelayPrecision::kHigh);
auto timer = std::unique_ptr<Timer>(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>(timer, TimerThreadDeleter(owner));
timers_[id] = unique_timer.get();
return unique_timer;
}
void

View File

@ -73,7 +73,8 @@ class TimerManager {
public:
explicit TimerManager(TimeoutCreator timeout_creator) : timeout_creator_(timeout_creator) {}
std::unique_ptr<Timer> CreateTimer(const std::string &name, Timer::OnExpired on_expired);
std::unique_ptr<Timer, TimerThreadDeleter>
CreateTimer(const std::string &name, Timer::OnExpired on_expired, TaskQueueBase *owner = nullptr);
void HandleTimeout(TimeoutID timeout_id);
private: