Symmetri
Loading...
Searching...
No Matches
tasks.h
Go to the documentation of this file.
1#pragma once
2
5#include <atomic>
6#include <functional>
7#include <memory>
8#include <thread>
9#include <vector>
10
11namespace symmetri {
12
17class TaskQueue;
18
31 public:
32 using Task = std::function<void()>;
33
40 explicit TaskSystem(size_t n_threads = std::thread::hardware_concurrency());
41 ~TaskSystem() noexcept;
42 TaskSystem(TaskSystem const&) = delete;
43 TaskSystem(TaskSystem&&) noexcept = delete;
44 TaskSystem& operator=(TaskSystem const&) = delete;
45 TaskSystem& operator=(TaskSystem&&) noexcept = delete;
46
52 void push(Task&& p) const;
53
54 private:
55 void loop();
56 std::vector<std::thread> pool_;
57 std::atomic<bool> is_running_;
58 std::unique_ptr<TaskQueue> queue_;
59};
60
61} // namespace symmetri
Create a TaskSystem object. The only way to create a TaskSystem is through this factory....
Definition tasks.h:30
void push(Task &&p) const
push tasks the queue for later execution on the thread pool.
Definition tasks.cpp:54
TaskSystem(size_t n_threads=std::thread::hardware_concurrency())
Construct a new Task System object with n threads.
Definition tasks.cpp:22