-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathintrusive_pool.h
45 lines (31 loc) · 870 Bytes
/
intrusive_pool.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// Created by konstantin on 19.06.24.
//
#pragma once
#include <atomic>
#include <memory>
#include <thread>
#include <vector>
#include <executor/executor.h>
#include <executor/task/task.h>
#include <executor/task/task_base.h>
#include <components/sync/spinLock.h>
namespace NExecutors {
class IntrusiveThreadPool final : public IExecutor {
public:
explicit IntrusiveThreadPool(size_t count);
~IntrusiveThreadPool() override;
void Start();
void Submit(TaskBase* task) override;
static IExecutor* Current();
void WaitShutdown();
private:
const size_t workers_count_;
std::vector<std::unique_ptr<std::thread>> workers_;
std::mutex mutex;
NComponents::IntrusiveList<TaskBase> tasks;
size_t count_workers_{0};
std::mutex mutex_workers_;
std::condition_variable empty_workers_;
};
} // namespace executors