OmniSciDB  c07336695a
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 38 of file ThreadController.h.

Constructor & Destructor Documentation

◆ SimpleThreadController() [1/3]

template<typename FutureReturnType = void>
ThreadController_NS::SimpleThreadController< FutureReturnType >::SimpleThreadController ( )
delete

◆ SimpleThreadController() [2/3]

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 42 of file ThreadController.h.

◆ SimpleThreadController() [3/3]

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 45 of file ThreadController.h.

48  : max_threads_(max_threads), future_getter_(future_getter) {}
const FutureGetter< FutureReturnType > future_getter_

◆ ~SimpleThreadController()

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

Definition at line 49 of file ThreadController.h.

49 {}

Member Function Documentation

◆ checkThreadsStatus()

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

Reimplemented in ThreadController_NS::SimpleRunningThreadController< FutureReturnType >.

Definition at line 52 of file ThreadController.h.

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

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

◆ finish()

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

Definition at line 73 of file ThreadController.h.

Referenced by Importer_NS::DataStreamSink::archivePlumber().

73  {
74  for (auto& t : threads_) {
75  get_future(t);
76  }
77  threads_.clear();
78  }
std::vector< std::future< FutureReturnType > > threads_
void get_future(std::future< FutureReturnType > &future, std::enable_if_t< future_return_void > *=0)
+ Here is the caller graph for this function:

◆ get_future() [1/2]

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 82 of file ThreadController.h.

83  {
84  future.get();
85  }

◆ get_future() [2/2]

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 87 of file ThreadController.h.

88  {
89  future_getter_.get(future.get());
90  }
const FutureGetter< FutureReturnType > future_getter_

◆ getRunningThreadCount()

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

Reimplemented in ThreadController_NS::SimpleRunningThreadController< FutureReturnType >.

Definition at line 51 of file ThreadController.h.

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

◆ getThreadCount()

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

Definition at line 50 of file ThreadController.h.

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

◆ startThread()

template<typename FutureReturnType = void>
template<typename FuncType , typename... Args>
void ThreadController_NS::SimpleThreadController< FutureReturnType >::startThread ( FuncType &&  func,
Args &&...  args 
)
inline

Definition at line 70 of file ThreadController.h.

References run-benchmark-import::args.

Referenced by Importer_NS::DataStreamSink::archivePlumber(), and ThreadController_NS::SimpleRunningThreadController< FutureReturnType >::startThread().

70  {
71  threads_.emplace_back(std::async(std::launch::async, func, args...));
72  }
std::vector< std::future< FutureReturnType > > threads_
+ Here is the caller graph for this function:

Member Data Documentation

◆ future_getter_

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

Definition at line 94 of file ThreadController.h.

◆ max_threads_

template<typename FutureReturnType = void>
const int ThreadController_NS::SimpleThreadController< FutureReturnType >::max_threads_
private

Definition at line 93 of file ThreadController.h.

◆ threads_

template<typename FutureReturnType = void>
std::vector<std::future<FutureReturnType> > ThreadController_NS::SimpleThreadController< FutureReturnType >::threads_
private

Definition at line 95 of file ThreadController.h.


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