Symmetri
Toggle main menu visibility
Loading...
Searching...
No Matches
tasks.h
Go to the documentation of this file.
1
#pragma once
2
4
5
#include <stddef.h>
6
7
#include <atomic>
8
#include <functional>
9
#include <memory>
10
#include <thread>
11
#include <vector>
12
13
namespace
symmetri {
14
19
class
TaskQueue
;
20
32
class
TaskSystem
{
33
public
:
34
using
Task = std::function<void()>;
35
42
explicit
TaskSystem
(
size_t
n_threads = std::thread::hardware_concurrency());
43
~TaskSystem
()
noexcept
;
44
TaskSystem
(
TaskSystem
const
&) =
delete
;
45
TaskSystem
(
TaskSystem
&&)
noexcept
=
delete
;
46
TaskSystem
& operator=(
TaskSystem
const
&) =
delete
;
47
TaskSystem
& operator=(
TaskSystem
&&)
noexcept
=
delete
;
48
54
void
push
(Task&& p)
const
;
55
56
private
:
57
void
loop();
58
std::vector<std::thread> pool_;
59
std::atomic<bool> is_running_;
60
std::unique_ptr<TaskQueue> queue_;
61
};
62
63
}
// namespace symmetri
symmetri::TaskQueue
TaskQueue is an inheritance based alias for a lock-free queue.
Definition
tasks.cpp:22
symmetri::TaskSystem::push
void push(Task &&p) const
push tasks the queue for later execution on the thread pool.
Definition
tasks.cpp:58
symmetri::TaskSystem::TaskSystem
TaskSystem(size_t n_threads=std::thread::hardware_concurrency())
Construct a new Task System object with n threads.
Definition
tasks.cpp:26
symmetri
include
symmetri
tasks.h
Generated by
1.17.0