Beatmup
Beatmup::Context::Impl::ThreadPoolEventListener Class Reference

Thread pool event listener. More...

Inheritance diagram for Beatmup::Context::Impl::ThreadPoolEventListener:
Beatmup::ThreadPool::EventListener

Public Member Functions

 ThreadPoolEventListener (const Context::Impl &ctx)
 
void threadCreated (PoolIndex pool)
 Callback function called when a new worker thread is created. More...
 
void threadTerminating (PoolIndex pool)
 Callback function called when a worker thread is terminating. More...
 
bool taskDone (PoolIndex pool, AbstractTask &task, bool aborted)
 Callback function called when a task is done or cancelled; if returns true, the task will be repeated. More...
 
void taskFail (PoolIndex pool, AbstractTask &task, std::exception_ptr exPtr)
 Callback function called when an exception is thrown. More...
 
void gpuInitFail (PoolIndex pool, std::exception_ptr exPtr)
 Callback function called when the GPU cannot start. More...
 

Private Attributes

const Context::Implctx
 

Detailed Description

Thread pool event listener.

Definition at line 48 of file context.cpp.

Constructor & Destructor Documentation

◆ ThreadPoolEventListener()

Beatmup::Context::Impl::ThreadPoolEventListener::ThreadPoolEventListener ( const Context::Impl ctx)
inline

Definition at line 53 of file context.cpp.

53 : ctx(ctx) {}

Member Function Documentation

◆ threadCreated()

void Beatmup::Context::Impl::ThreadPoolEventListener::threadCreated ( PoolIndex  pool)
inlinevirtual

Callback function called when a new worker thread is created.

Parameters
poolThread pool number in the context

Reimplemented from Beatmup::ThreadPool::EventListener.

Definition at line 55 of file context.cpp.

55  {
56  if (ctx.eventListener)
58  };
virtual void threadCreated(PoolIndex pool)=0
Called when a new worker thread is created.
Context::EventListener * eventListener
an event listener
Definition: context.cpp:116

◆ threadTerminating()

void Beatmup::Context::Impl::ThreadPoolEventListener::threadTerminating ( PoolIndex  pool)
inlinevirtual

Callback function called when a worker thread is terminating.

Parameters
poolThread pool number in the context

Reimplemented from Beatmup::ThreadPool::EventListener.

Definition at line 60 of file context.cpp.

60  {
61  if (ctx.eventListener)
63  };
virtual void threadTerminating(PoolIndex pool)=0
Called when a worker thread finished.

◆ taskDone()

bool Beatmup::Context::Impl::ThreadPoolEventListener::taskDone ( PoolIndex  pool,
AbstractTask task,
bool  aborted 
)
inlinevirtual

Callback function called when a task is done or cancelled; if returns true, the task will be repeated.

Parameters
poolThread pool number in the context
taskThe task
abortedIf true, the task was aborted

Reimplemented from Beatmup::ThreadPool::EventListener.

Definition at line 65 of file context.cpp.

65  {
66  if (ctx.eventListener)
67  return ctx.eventListener->taskDone(pool, task, aborted);
68  return false;
69  };
virtual bool taskDone(PoolIndex pool, AbstractTask &task, bool aborted)=0
Called when a task is successfully finished.
Beatmup::NNets::InferenceTask * task

◆ taskFail()

void Beatmup::Context::Impl::ThreadPoolEventListener::taskFail ( PoolIndex  pool,
AbstractTask task,
std::exception_ptr  exPtr 
)
inlinevirtual

Callback function called when an exception is thrown.

Parameters
poolThread pool number in the context
taskThe task that was running when the exception was thrown
exPtrException pointer

Reimplemented from Beatmup::ThreadPool::EventListener.

Definition at line 71 of file context.cpp.

71  {
72  if (ctx.eventListener)
73  try {
74  std::rethrow_exception(exPtr);
75  }
76  catch (const std::exception & ex) {
77 #if BEATMUP_PLATFORM_ANDROID
78  __android_log_print(ANDROID_LOG_ERROR, "Beatmup",
79  "\n********************************************\n"
80  "Beatmup engine raises exception:\n%s"
81  "\n********************************************\n", ex.what());
82 #elif BEATMUP_DEBUG
83  std::cout << ex.what() << std::endl;
84 #endif
85  ctx.eventListener->taskFail(pool, task, ex);
86  }
87  }
virtual void taskFail(PoolIndex pool, AbstractTask &task, const std::exception &ex)=0
Called when a task fails.

◆ gpuInitFail()

void Beatmup::Context::Impl::ThreadPoolEventListener::gpuInitFail ( PoolIndex  pool,
std::exception_ptr  exPtr 
)
inlinevirtual

Callback function called when the GPU cannot start.

Parameters
poolThread pool number in the context
exPtrException pointer; points to the exception instance occurred when starting up the GPU

Reimplemented from Beatmup::ThreadPool::EventListener.

Definition at line 89 of file context.cpp.

89  {
90  if (ctx.eventListener)
91  try {
92  std::rethrow_exception(exPtr);
93  }
94  catch (const std::exception & ex) {
95 #if BEATMUP_PLATFORM_ANDROID
96  __android_log_print(ANDROID_LOG_ERROR, "Beatmup",
97  "\n********************************************\n"
98  "Beatmup engine was unable to init GPU:\n%s"
99  "\n********************************************\n", ex.what());
100 #elif BEATMUP_DEBUG
101  std::cout << ex.what() << std::endl;
102 #endif
103  ctx.eventListener->gpuInitFail(pool, ex);
104  }
105  }
virtual void gpuInitFail(PoolIndex pool, const std::exception &ex)=0
Called when GPU initialization failed.

Member Data Documentation

◆ ctx

const Context::Impl& Beatmup::Context::Impl::ThreadPoolEventListener::ctx
private

Definition at line 50 of file context.cpp.


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