1#ifndef OSMIUM_THREAD_POOL_HPP
2#define OSMIUM_THREAD_POOL_HPP
63 inline int get_pool_size(
int num_threads,
int user_setting,
unsigned hardware_concurrency) {
64 if (num_threads == 0) {
65 num_threads = user_setting ? user_setting : -2;
68 if (num_threads < 0) {
69 num_threads +=
static_cast<int>(hardware_concurrency);
72 if (num_threads < 1) {
74 }
else if (num_threads > max_pool_threads) {
75 num_threads = max_pool_threads;
81 inline std::size_t get_work_queue_size() noexcept {
114 if (thread.joinable()) {
132 if (task && task()) {
166 m_work_queue(max_queue_size > 0 ? max_queue_size :
detail::get_work_queue_size(),
"work"),
220#if defined(__cpp_lib_is_invocable) && __cpp_lib_is_invocable >= 201703
223 template <
typename TFunction>
227 template <
typename TFunction>
231 template <
typename TFunction>
232 std::future<submit_func_result_type<TFunction>>
submit(TFunction&& func) {
233 std::packaged_task<submit_func_result_type<TFunction>()> task{std::forward<TFunction>(func)};
234 std::future<submit_func_result_type<TFunction>> future_result{task.get_future()};
237 return future_result;
thread_joiner(std::vector< std::thread > &threads)
Definition: pool.hpp:102
thread_joiner(thread_joiner &&)=delete
std::vector< std::thread > & m_threads
Definition: pool.hpp:98
thread_joiner(const thread_joiner &)=delete
thread_joiner & operator=(thread_joiner &&)=delete
thread_joiner & operator=(const thread_joiner &)=delete
~thread_joiner()
Definition: pool.hpp:112
void shutdown_all_workers()
Definition: pool.hpp:191
std::vector< std::thread > m_threads
Definition: pool.hpp:123
@ default_queue_size
Definition: pool.hpp:147
~Pool()
Definition: pool.hpp:204
Pool(int num_threads=default_num_threads, std::size_t max_queue_size=default_queue_size)
Definition: pool.hpp:165
std::size_t queue_size() const
Definition: pool.hpp:212
typename std::result_of< TFunction()>::type submit_func_result_type
Definition: pool.hpp:228
std::future< submit_func_result_type< TFunction > > submit(TFunction &&func)
Definition: pool.hpp:232
static Pool & default_instance()
Definition: pool.hpp:186
Pool(const Pool &)=delete
@ default_num_threads
Definition: pool.hpp:143
Pool & operator=(Pool &&)=delete
osmium::thread::Queue< function_wrapper > m_work_queue
Definition: pool.hpp:122
thread_joiner m_joiner
Definition: pool.hpp:124
bool queue_empty() const
Definition: pool.hpp:216
void worker_thread()
Definition: pool.hpp:127
int m_num_threads
Definition: pool.hpp:125
Pool & operator=(const Pool &)=delete
int num_threads() const noexcept
Definition: pool.hpp:208
Definition: function_wrapper.hpp:48
int get_pool_threads() noexcept
Definition: config.hpp:62
std::size_t get_max_queue_size(const char *queue_name, const std::size_t default_value) noexcept
Definition: config.hpp:83
type
Definition: entity_bits.hpp:63
void set_thread_name(const char *name) noexcept
Definition: util.hpp:78
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
Definition: location.hpp:555