#pragma once #include "BS_thread_pool.hpp" /** * @brief Simple wrapper around BS::thread_pool that makes a BS::thread_pool a * singleton, such that a thread pool can be used around in the code, and * safely spawn threads also from other threads. Only wraps a submit() and * push_task for now. */ class GlobalThreadPool { /** * @brief Shared access to the thread pool. */ std::shared_ptr _pool; public: /** * @brief Instantiate handle to the thread pool. */ GlobalThreadPool(); GlobalThreadPool(const GlobalThreadPool &) = default; GlobalThreadPool &operator=(const GlobalThreadPool &) = default; /** * @brief Wrapper around BS::thread_pool::submit(...) */ template < typename F, typename... A, typename R = std::invoke_result_t, std::decay_t...>> [[nodiscard]] std::future submit(F &&task, A &&...args) { return _pool->submit(task, args...); } /** * @brief Wrapper around BS::thread_pool::push_task(...) */ template void push_task(F &&task, A &&...args) { _pool->push_task(task, args...); } };