OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ThreadController_NS::SimpleThreadController< FutureReturnType > Class Template Reference

#include <ThreadController.h>

+ Inheritance diagram for ThreadController_NS::SimpleThreadController< FutureReturnType >:

Public Member Functions

 SimpleThreadController ()=delete
 
template<bool future_return_void = std::is_void<FutureReturnType>::value>
 SimpleThreadController (const int max_threads, std::enable_if_t< future_return_void > *=0)
 
template<bool future_return_void = std::is_void<FutureReturnType>::value>
 SimpleThreadController (const int max_threads, const FutureGetter< FutureReturnType > future_getter, std::enable_if_t<!future_return_void > *=0)
 
virtual ~SimpleThreadController ()
 
virtual int getThreadCount () const
 
virtual int getRunningThreadCount () const
 
virtual void checkThreadsStatus ()
 
template<typename FuncType , typename... Args>
void startThread (FuncType &&func, Args &&...args)
 
virtual void finish ()
 

Protected Member Functions

template<bool future_return_void = std::is_void<FutureReturnType>::value>
void get_future (std::future< FutureReturnType > &future, std::enable_if_t< future_return_void > *=0)
 
template<bool future_return_void = std::is_void<FutureReturnType>::value>
void get_future (std::future< FutureReturnType > &future, std::enable_if_t<!future_return_void > *=0)
 

Private Attributes

const int max_threads_
 
const FutureGetter
< FutureReturnType > 
future_getter_ {}
 
std::vector< std::future
< FutureReturnType > > 
threads_
 

Detailed Description

template<typename FutureReturnType = void>
class ThreadController_NS::SimpleThreadController< FutureReturnType >

Definition at line 39 of file ThreadController.h.

Constructor & Destructor Documentation

template<typename FutureReturnType = void>
ThreadController_NS::SimpleThreadController< FutureReturnType >::SimpleThreadController ( )
delete
template<typename FutureReturnType = void>
template<bool future_return_void = std::is_void<FutureReturnType>::value>
ThreadController_NS::SimpleThreadController< FutureReturnType >::SimpleThreadController ( const int  max_threads,
std::enable_if_t< future_return_void > *  = 0 
)
inline

Definition at line 43 of file ThreadController.h.

44  : max_threads_(max_threads) {}
template<typename FutureReturnType = void>
template<bool future_return_void = std::is_void<FutureReturnType>::value>
ThreadController_NS::SimpleThreadController< FutureReturnType >::SimpleThreadController ( const int  max_threads,
const FutureGetter< FutureReturnType >  future_getter,
std::enable_if_t<!future_return_void > *  = 0 
)
inline

Definition at line 46 of file ThreadController.h.

49  : max_threads_(max_threads), future_getter_(future_getter) {}
const FutureGetter< FutureReturnType > future_getter_
template<typename FutureReturnType = void>
virtual ThreadController_NS::SimpleThreadController< FutureReturnType >::~SimpleThreadController ( )
inlinevirtual

Definition at line 50 of file ThreadController.h.

50 {}

Member Function Documentation

template<typename FutureReturnType = void>
virtual void ThreadController_NS::SimpleThreadController< FutureReturnType >::checkThreadsStatus ( )
inlinevirtual

Reimplemented in ThreadController_NS::SimpleRunningThreadController< FutureReturnType >.

Definition at line 53 of file ThreadController.h.

References ThreadController_NS::SimpleThreadController< FutureReturnType >::get_future(), ThreadController_NS::SimpleThreadController< FutureReturnType >::getRunningThreadCount(), ThreadController_NS::SimpleThreadController< FutureReturnType >::max_threads_, and ThreadController_NS::SimpleThreadController< FutureReturnType >::threads_.

Referenced by ThreadController_NS::SimpleRunningThreadController< FutureReturnType >::checkThreadsStatus(), and anonymous_namespace{TableArchiver.cpp}::update_or_drop_column_ids_in_table_files().

53  {
54  while (getRunningThreadCount() >= max_threads_) {
55  std::this_thread::yield();
56  threads_.erase(std::remove_if(threads_.begin(),
57  threads_.end(),
58  [this](auto& th) {
59  using namespace std::chrono_literals;
60  if (th.wait_for(0ns) == std::future_status::ready) {
61  this->get_future(th);
62  return true;
63  } else {
64  return false;
65  }
66  }),
67  threads_.end());
68  }
69  }
std::vector< std::future< FutureReturnType > > threads_
void get_future(std::future< FutureReturnType > &future, std::enable_if_t< future_return_void > *=0)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename FutureReturnType = void>
virtual void ThreadController_NS::SimpleThreadController< FutureReturnType >::finish ( )
inlinevirtual

Definition at line 74 of file ThreadController.h.

References ThreadController_NS::SimpleThreadController< FutureReturnType >::get_future(), and ThreadController_NS::SimpleThreadController< FutureReturnType >::threads_.

Referenced by anonymous_namespace{TableArchiver.cpp}::update_or_drop_column_ids_in_table_files().

74  {
75  for (auto& t : threads_) {
76  get_future(t);
77  }
78  threads_.clear();
79  }
std::vector< std::future< FutureReturnType > > threads_
void get_future(std::future< FutureReturnType > &future, std::enable_if_t< future_return_void > *=0)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename FutureReturnType = void>
template<bool future_return_void = std::is_void<FutureReturnType>::value>
void ThreadController_NS::SimpleThreadController< FutureReturnType >::get_future ( std::future< FutureReturnType > &  future,
std::enable_if_t< future_return_void > *  = 0 
)
inlineprotected

Definition at line 83 of file ThreadController.h.

Referenced by ThreadController_NS::SimpleThreadController< FutureReturnType >::checkThreadsStatus(), and ThreadController_NS::SimpleThreadController< FutureReturnType >::finish().

84  {
85  future.get();
86  }

+ Here is the caller graph for this function:

template<typename FutureReturnType = void>
template<bool future_return_void = std::is_void<FutureReturnType>::value>
void ThreadController_NS::SimpleThreadController< FutureReturnType >::get_future ( std::future< FutureReturnType > &  future,
std::enable_if_t<!future_return_void > *  = 0 
)
inlineprotected

Definition at line 88 of file ThreadController.h.

References ThreadController_NS::SimpleThreadController< FutureReturnType >::future_getter_.

89  {
90  future_getter_.get(future.get());
91  }
const FutureGetter< FutureReturnType > future_getter_
template<typename FutureReturnType = void>
virtual int ThreadController_NS::SimpleThreadController< FutureReturnType >::getRunningThreadCount ( ) const
inlinevirtual

Reimplemented in ThreadController_NS::SimpleRunningThreadController< FutureReturnType >.

Definition at line 52 of file ThreadController.h.

References ThreadController_NS::SimpleThreadController< FutureReturnType >::threads_.

Referenced by ThreadController_NS::SimpleThreadController< FutureReturnType >::checkThreadsStatus().

52 { return threads_.size(); }
std::vector< std::future< FutureReturnType > > threads_

+ Here is the caller graph for this function:

template<typename FutureReturnType = void>
virtual int ThreadController_NS::SimpleThreadController< FutureReturnType >::getThreadCount ( ) const
inlinevirtual

Definition at line 51 of file ThreadController.h.

References ThreadController_NS::SimpleThreadController< FutureReturnType >::threads_.

51 { return threads_.size(); }
std::vector< std::future< FutureReturnType > > threads_
template<typename FutureReturnType = void>
template<typename FuncType , typename... Args>
void ThreadController_NS::SimpleThreadController< FutureReturnType >::startThread ( FuncType &&  func,
Args &&...  args 
)
inline

Definition at line 71 of file ThreadController.h.

References run_benchmark_import::args, threading_serial::async(), and ThreadController_NS::SimpleThreadController< FutureReturnType >::threads_.

Referenced by ThreadController_NS::SimpleRunningThreadController< FutureReturnType >::startThread(), and anonymous_namespace{TableArchiver.cpp}::update_or_drop_column_ids_in_table_files().

71  {
72  threads_.emplace_back(std::async(std::launch::async, func, args...));
73  }
std::vector< std::future< FutureReturnType > > threads_
future< Result > async(Fn &&fn, Args &&...args)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

template<typename FutureReturnType = void>
const FutureGetter<FutureReturnType> ThreadController_NS::SimpleThreadController< FutureReturnType >::future_getter_ {}
private
template<typename FutureReturnType = void>
const int ThreadController_NS::SimpleThreadController< FutureReturnType >::max_threads_
private

The documentation for this class was generated from the following file: