pica/taskmanager/manager.h

41 lines
775 B
C++

//SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
//SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <queue>
#include <vector>
#include <thread>
#include <memory>
#include <mutex>
#include <condition_variable>
#include "job.h"
namespace TM {
class Manager {
public:
Manager();
Manager(const Manager&) = delete;
Manager(Manager&&) = delete;
~Manager();
Manager& operator = (const Manager&) = delete;
Manager& operator = (Manager&&) = delete;
void start();
void stop();
void schedule(std::unique_ptr<Job> job);
private:
void loop();
private:
bool terminating;
std::vector<std::thread> threads;
std::queue<std::unique_ptr<Job>> queue;
std::mutex mtx;
std::condition_variable cond;
};
}