Commit e730d57c authored by tqcq's avatar tqcq
Browse files

feat support build thread deleter with timer

parent 216a5c1d
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -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
+2 −1
Original line number Diff line number Diff line
@@ -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: