rexlib 0.1.0
Device-agnostic array computing library for CryoEM and CryoET image processing, with a pluggable backend architecture
Loading...
Searching...
No Matches
thread_pool.hpp
1// SPDX-License-Identifier: GPL-3.0-only
2
3#pragma once
4
5#include <rexlib/core/platform/dynamic_shared_object.h>
6
7#include <cstddef>
8#include <memory>
9
10namespace rexlib
11{
12namespace cpu
13{
14
15class thread_pool_implementation;
16
38{
39public:
48 void (*)(const void *context, std::size_t begin, std::size_t end);
49
57 REXLIB_API
58 explicit thread_pool(std::size_t worker_count);
59
60 thread_pool(const thread_pool &other) = delete;
61 thread_pool(thread_pool &&other) = delete;
62
63 REXLIB_API
65
66 thread_pool& operator=(const thread_pool &other) = delete;
67 thread_pool& operator=(thread_pool &&other) = delete;
68
76 REXLIB_API
77 std::size_t get_size() const noexcept;
78
110 REXLIB_API
111 void run(
112 std::size_t count,
113 std::size_t grain_size,
114 body_function body,
115 const void *context
116 );
117
133 REXLIB_API
134 static std::size_t get_default_worker_count();
135
136private:
137 std::unique_ptr<thread_pool_implementation> m_implementation;
138};
139
140} // namespace cpu
141} // namespace rexlib
A fixed set of threads a loop's iterations are spread over.
Definition thread_pool.hpp:38
void(*)(const void *context, std::size_t begin, std::size_t end) body_function
The type-erased body of a parallel loop.
Definition thread_pool.hpp:48
static std::size_t get_default_worker_count()
How many workers a pool spawns when nothing else says otherwise.
void run(std::size_t count, std::size_t grain_size, body_function body, const void *context)
Run a loop, splitting it across this pool.
std::size_t get_size() const noexcept
Get the number of threads a job is spread over.
thread_pool(std::size_t worker_count)
Construct a pool with a given number of worker threads.
Arrays, the operations on them and the devices that run those operations.
Definition cpu_device.hpp:10
REXLIB_CONSTEXPR std::size_t end() noexcept
Get the value representing the end of an array to be used as count.
@ cpu
CPU of the host node.