//SPDX-FileCopyrightText: 2023 Yury Gubich //SPDX-License-Identifier: GPL-3.0-or-later #pragma once #include #include #include #include #include #include #include #include "manager.h" #include "utils/helpers.h" namespace TM { class Scheduler { public: using Delay = std::chrono::milliseconds; using Task = std::function; Scheduler (std::weak_ptr manager); ~Scheduler (); void start(); void stop(); void schedule(Task task, Delay delay); private: void loop(); private: using Time = std::chrono::time_point; using Record = std::pair; std::weak_ptr manager; std::priority_queue< Record, std::vector, FirstGreater > queue; std::mutex mutex; std::condition_variable cond; std::unique_ptr thread; bool running; }; }