Libosmium
2.15.4
Fast and flexible C++ library for working with OpenStreetMap data
|
Go to the documentation of this file. 1 #ifndef OSMIUM_THREAD_POOL_HPP
2 #define OSMIUM_THREAD_POOL_HPP
44 #include <type_traits>
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 += 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"),
214 template <
typename TFunction>
215 std::future<
typename std::result_of<TFunction()>
::type>
submit(TFunction&& func) {
216 using result_type =
typename std::result_of<TFunction()>
::type;
218 std::packaged_task<result_type()> task{std::forward<TFunction>(func)};
219 std::future<result_type> future_result{task.get_future()};
222 return future_result;
231 #endif // OSMIUM_THREAD_POOL_HPP
bool queue_empty() const
Definition: pool.hpp:210
~Pool()
Definition: pool.hpp:198
Definition: function_wrapper.hpp:48
std::future< typename std::result_of< TFunction()>::type > submit(TFunction &&func)
Definition: pool.hpp:215
void set_thread_name(const char *name) noexcept
Definition: util.hpp:76
std::size_t get_max_queue_size(const char *queue_name, const std::size_t default_value) noexcept
Definition: config.hpp:83
static Pool & default_instance()
Definition: pool.hpp:180
Pool & operator=(const Pool &)=delete
@ default_queue_size
Definition: pool.hpp:147
osmium::thread::Queue< function_wrapper > m_work_queue
Definition: pool.hpp:122
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
std::size_t queue_size() const
Definition: pool.hpp:206
void worker_thread()
Definition: pool.hpp:127
int num_threads() const noexcept
Definition: pool.hpp:202
void shutdown_all_workers()
Definition: pool.hpp:185
thread_joiner m_joiner
Definition: pool.hpp:124
int get_pool_threads() noexcept
Definition: config.hpp:62
Definition: location.hpp:550
std::vector< std::thread > & m_threads
Definition: pool.hpp:98
int m_num_threads
Definition: pool.hpp:125
thread_joiner(std::vector< std::thread > &threads)
Definition: pool.hpp:102
~thread_joiner()
Definition: pool.hpp:112
std::vector< std::thread > m_threads
Definition: pool.hpp:123
Pool(int num_threads=default_num_threads, std::size_t max_queue_size=default_queue_size)
Definition: pool.hpp:165
thread_joiner & operator=(const thread_joiner &)=delete
type
Definition: entity_bits.hpp:63
@ default_num_threads
Definition: pool.hpp:143