24 #include <type_traits>
27 namespace ThreadController_NS {
29 template <
typename FutureReturnType>
38 template <
typename FutureReturnType =
void>
42 template <bool future_return_void = std::is_void<FutureReturnType>::value>
45 template <bool future_return_void = std::is_void<FutureReturnType>::value>
48 std::enable_if_t<!future_return_void>* = 0)
55 std::this_thread::yield();
59 using namespace std::chrono_literals;
60 if (th.wait_for(0ns) == std::future_status::ready) {
70 template <
typename FuncType,
typename... Args>
82 template <bool future_return_void = std::is_void<FutureReturnType>::value>
84 std::enable_if_t<future_return_void>* = 0) {
87 template <bool future_return_void = std::is_void<FutureReturnType>::value>
89 std::enable_if_t<!future_return_void>* = 0) {
96 std::vector<std::future<FutureReturnType>>
threads_;
99 template <
typename FutureReturnType =
void>
103 template <bool future_return_void = std::is_void<FutureReturnType>::value>
105 std::enable_if_t<future_return_void>* = 0)
107 template <bool future_return_void = std::is_void<FutureReturnType>::value>
110 std::enable_if_t<!future_return_void>* = 0)
112 , n_running_threads_(0) {}
119 template <
typename FuncType,
typename... Args>
122 return ++n_running_threads_;
std::vector< std::future< FutureReturnType > > threads_
const FutureGetter< FutureReturnType > future_getter_
SimpleThreadController(const int max_threads, const FutureGetter< FutureReturnType > future_getter, std::enable_if_t<!future_return_void > *=0)
void startThread(FuncType &&func, Args &&...args)
virtual int getThreadCount() const
virtual void checkThreadsStatus()
~SimpleRunningThreadController() override
virtual int getRunningThreadCount() const
future< Result > async(Fn &&fn, Args &&...args)
virtual ~SimpleThreadController()
SimpleRunningThreadController(const int max_threads, const FutureGetter< FutureReturnType > future_getter, std::enable_if_t<!future_return_void > *=0)
SimpleRunningThreadController(const int max_threads, std::enable_if_t< future_return_void > *=0)
void(*)(FutureReturnType) FutureGetterFunction
int getRunningThreadCount() const override
void get_future(std::future< FutureReturnType > &future, std::enable_if_t<!future_return_void > *=0)
void checkThreadsStatus() override
std::atomic< int > n_running_threads_
int startThread(FuncType &&func, Args &&...args)
void get_future(std::future< FutureReturnType > &future, std::enable_if_t< future_return_void > *=0)
int notify_thread_is_completed()
SimpleThreadController()=delete
SimpleThreadController(const int max_threads, std::enable_if_t< future_return_void > *=0)