Beatmup
Beatmup::Context::Impl Class Reference

Context class implementation (pimpl) More...

Classes

class  ThreadPoolEventListener
 Thread pool event listener. More...
 

Public Member Functions

 Impl (const PoolIndex numThreadPools)
 
 ~Impl ()
 
float performTask (PoolIndex pool, AbstractTask &task)
 
void repeatTask (PoolIndex pool, AbstractTask &task, bool abortCurrent)
 
Job submitTask (const PoolIndex pool, AbstractTask &task)
 
Job submitPersistentTask (const PoolIndex pool, AbstractTask &task)
 
void waitForJob (const PoolIndex pool, Job job)
 
bool abortJob (const PoolIndex pool, Job job)
 
void wait (const PoolIndex pool)
 
bool busy (const PoolIndex pool)
 
void check (const PoolIndex pool)
 
const ThreadIndex maxAllowedWorkerCount (const PoolIndex pool) const
 
void limitWorkerCount (const PoolIndex pool, ThreadIndex maxValue)
 
bool isGpuQueried () const
 
bool isGpuReady () const
 
bool isManagingThread () const
 

Public Attributes

Context::EventListenereventListener
 an event listener More...
 

Private Attributes

ThreadIndex optimalThreadCount
 optimal default number of worker threads per task in each pool More...
 
ThreadPool ** threadPools
 thread pools of task workers More...
 
PoolIndex numThreadPools
 
ThreadPoolEventListener threadPoolEventListener
 

Detailed Description

Context class implementation (pimpl)

Definition at line 43 of file context.cpp.

Constructor & Destructor Documentation

◆ Impl()

Beatmup::Context::Impl::Impl ( const PoolIndex  numThreadPools)
inline

Definition at line 118 of file context.cpp.

118  :
119  optimalThreadCount(std::max<ThreadIndex>(1, ThreadPool::hardwareConcurrency() / numThreadPools)),
122  eventListener(nullptr)
123  {
125  for (PoolIndex pool = 0; pool < numThreadPools; pool++)
127  }
A pool of threads running tasks ThreadPool runs AbstractTasks, possibly in multiple threads.
Definition: thread_pool.hpp:36
PoolIndex numThreadPools
Definition: context.cpp:111
Context::EventListener * eventListener
an event listener
Definition: context.cpp:116
ThreadPool ** threadPools
thread pools of task workers
Definition: context.cpp:110
ThreadIndex optimalThreadCount
optimal default number of worker threads per task in each pool
Definition: context.cpp:108
ThreadPoolEventListener threadPoolEventListener
Definition: context.cpp:112
unsigned char PoolIndex
number of tread pools or a pool index
Definition: parallelism.h:67

◆ ~Impl()

Beatmup::Context::Impl::~Impl ( )
inline

Definition at line 130 of file context.cpp.

130  {
131  for (PoolIndex i = 0; i < numThreadPools; i++)
132  delete threadPools[i];
133  delete[] threadPools;
134  }

Member Function Documentation

◆ performTask()

float Beatmup::Context::Impl::performTask ( PoolIndex  pool,
AbstractTask task 
)
inline

Definition at line 137 of file context.cpp.

137  {
139  auto startTime = std::chrono::high_resolution_clock::now();
140  Job job = threadPools[pool]->submitTask(task, ThreadPool::TaskExecutionMode::NORMAL);
141  threadPools[pool]->waitForJob(job);
142  auto endTime = std::chrono::high_resolution_clock::now();
143  threadPools[pool]->check();
144  return std::chrono::duration<float, std::milli>(endTime - startTime).count();
145  }
Job submitTask(AbstractTask &task, const TaskExecutionMode mode)
Adds a new task to the jobs queue.
void waitForJob(Job job)
Blocks until a given job finishes if not yet.
void check()
Checks if the thread pool is doing great.
#define BEATMUP_ASSERT_DEBUG(C)
Definition: exception.h:163
int Job
Definition: parallelism.h:69
JNIEnv jlong jint jint job
Beatmup::NNets::InferenceTask * task

◆ repeatTask()

void Beatmup::Context::Impl::repeatTask ( PoolIndex  pool,
AbstractTask task,
bool  abortCurrent 
)
inline

Definition at line 148 of file context.cpp.

148  {
150  threadPools[pool]->repeatTask(task, abortCurrent);
151  }
Job repeatTask(AbstractTask &task, bool abortCurrent)
Ensures a given task executed at least once.

◆ submitTask()

Job Beatmup::Context::Impl::submitTask ( const PoolIndex  pool,
AbstractTask task 
)
inline

Definition at line 154 of file context.cpp.

154  {
156  return threadPools[pool]->submitTask(task, ThreadPool::TaskExecutionMode::NORMAL);
157  }

◆ submitPersistentTask()

Job Beatmup::Context::Impl::submitPersistentTask ( const PoolIndex  pool,
AbstractTask task 
)
inline

Definition at line 160 of file context.cpp.

160  {
162  return threadPools[pool]->submitTask(task, ThreadPool::TaskExecutionMode::PERSISTENT);
163  }

◆ waitForJob()

void Beatmup::Context::Impl::waitForJob ( const PoolIndex  pool,
Job  job 
)
inline

Definition at line 166 of file context.cpp.

166  {
168  threadPools[pool]->waitForJob(job);
169  }

◆ abortJob()

bool Beatmup::Context::Impl::abortJob ( const PoolIndex  pool,
Job  job 
)
inline

Definition at line 172 of file context.cpp.

172  {
174  return threadPools[pool]->abortJob(job);
175  }
bool abortJob(Job job)
Aborts a given submitted job.

◆ wait()

void Beatmup::Context::Impl::wait ( const PoolIndex  pool)
inline

Definition at line 178 of file context.cpp.

178  {
180  threadPools[pool]->wait();
181  }
void wait()
Blocks until all the submitted jobs are executed.

◆ busy()

bool Beatmup::Context::Impl::busy ( const PoolIndex  pool)
inline

Definition at line 184 of file context.cpp.

184  {
186  return threadPools[pool]->busy();
187  }
bool busy()
Checks whether the pool has jobs.

◆ check()

void Beatmup::Context::Impl::check ( const PoolIndex  pool)
inline

Definition at line 190 of file context.cpp.

190  {
191  threadPools[pool]->check();
192  }

◆ maxAllowedWorkerCount()

const ThreadIndex Beatmup::Context::Impl::maxAllowedWorkerCount ( const PoolIndex  pool) const
inline

Definition at line 195 of file context.cpp.

195  {
197  return threadPools[pool]->getThreadCount();
198  }
ThreadIndex getThreadCount() const

◆ limitWorkerCount()

void Beatmup::Context::Impl::limitWorkerCount ( const PoolIndex  pool,
ThreadIndex  maxValue 
)
inline

Definition at line 201 of file context.cpp.

201  {
203  threadPools[pool]->resize(maxValue);
204  }
void resize(ThreadIndex newThreadCount)
Resizes the pool.

◆ isGpuQueried()

bool Beatmup::Context::Impl::isGpuQueried ( ) const
inline

Definition at line 207 of file context.cpp.

207  {
208  return threadPools[0]->isGpuQueried();
209  }
bool isGpuQueried() const

◆ isGpuReady()

bool Beatmup::Context::Impl::isGpuReady ( ) const
inline

Definition at line 212 of file context.cpp.

212  {
213  return threadPools[0]->isGpuReady();
214  }
bool isGpuReady() const

◆ isManagingThread()

bool Beatmup::Context::Impl::isManagingThread ( ) const
inline

Definition at line 217 of file context.cpp.

217  {
218  for (PoolIndex pool = 0; pool < numThreadPools; ++pool)
219  if (threadPools[pool]->isManagingThread())
220  return true;
221  return false;
222  }
bool isManagingThread() const
Definition: context.cpp:217

Member Data Documentation

◆ optimalThreadCount

ThreadIndex Beatmup::Context::Impl::optimalThreadCount
private

optimal default number of worker threads per task in each pool

Definition at line 108 of file context.cpp.

◆ threadPools

ThreadPool** Beatmup::Context::Impl::threadPools
private

thread pools of task workers

Definition at line 110 of file context.cpp.

◆ numThreadPools

PoolIndex Beatmup::Context::Impl::numThreadPools
private

Definition at line 111 of file context.cpp.

◆ threadPoolEventListener

ThreadPoolEventListener Beatmup::Context::Impl::threadPoolEventListener
private

Definition at line 112 of file context.cpp.

◆ eventListener

Context::EventListener* Beatmup::Context::Impl::eventListener

an event listener

Definition at line 116 of file context.cpp.


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