// Copyright (C) 2025 Simon Quigley // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . #ifndef TASK_QUEUE_H #define TASK_QUEUE_H #include "ci_database_objs.h" #include #include #include #include #include #include #include #include #include class TaskQueue { public: TaskQueue(size_t max_concurrent_tasks = 10); ~TaskQueue(); void enqueue(std::shared_ptr jobstatus, std::function log)> task_func, std::shared_ptr packageconf); void start(); void stop(); std::set, Task::TaskComparator> get_tasks() const; std::set, Task::TaskComparator> get_running_tasks() const; private: size_t max_concurrent_tasks_; std::set, Task::TaskComparator> tasks_; std::set, Task::TaskComparator> running_tasks_; std::set> running_pkgconfs_; std::queue> thread_pool_tasks_; mutable std::mutex tasks_mutex_; mutable std::mutex running_pkgconfs_mutex_; mutable std::mutex running_tasks_mutex_; std::condition_variable cv_; bool stop_; std::vector workers_; int max_worker_id = 1; void worker_thread(); }; #endif // TASK_QUEUE_H