knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
knowrob::ThreadPool::LambdaRunner Class Reference

#include <ThreadPool.h>

Inheritance diagram for knowrob::ThreadPool::LambdaRunner:
Collaboration diagram for knowrob::ThreadPool::LambdaRunner:

Public Types

using StopChecker = std::function< bool()>
 
using StopChecker = std::function< bool()>
 

Public Member Functions

 LambdaRunner (const std::function< void(const StopChecker &)> &fn)
 
void run () override
 
 LambdaRunner (const std::function< void(const StopChecker &)> &fn)
 
void run () override
 
- Public Member Functions inherited from knowrob::ThreadPool::Runner
 Runner ()
 
virtual ~Runner ()
 
 Runner (const Runner &)=delete
 
void join ()
 
void stop (bool wait)
 
bool hasStopRequest () const
 
bool isTerminated () const
 
 Runner ()
 
virtual ~Runner ()
 
 Runner (const Runner &)=delete
 
void join ()
 
void stop (bool wait)
 
bool hasStopRequest () const
 
bool isTerminated () const
 

Protected Attributes

std::function< void(const StopChecker &)> fn_
 
- Protected Attributes inherited from knowrob::ThreadPool::Runner
std::atomic< bool > isTerminated_
 
std::atomic< bool > isRunning_
 
std::atomic< bool > hasStopRequest_
 
std::mutex mutex_
 
std::condition_variable finishedCV_
 
ExceptionHandler exceptionHandler_
 

Additional Inherited Members

- Protected Member Functions inherited from knowrob::ThreadPool::Runner
void runInternal ()
 
void setExceptionHandler (ExceptionHandler exceptionHandler)
 
void runInternal ()
 
void setExceptionHandler (ExceptionHandler exceptionHandler)
 

Detailed Description

A runner that executes a lambda function.

Definition at line 150 of file ThreadPool.h.

Member Typedef Documentation

◆ StopChecker [1/2]

using knowrob::ThreadPool::LambdaRunner::StopChecker = std::function<bool()>

Definition at line 152 of file ThreadPool.h.

◆ StopChecker [2/2]

using knowrob::ThreadPool::LambdaRunner::StopChecker = std::function<bool()>

Definition at line 152 of file ThreadPool.h.

Constructor & Destructor Documentation

◆ LambdaRunner() [1/2]

knowrob::ThreadPool::LambdaRunner::LambdaRunner ( const std::function< void(const StopChecker &)> &  fn)
inlineexplicit
Parameters
fnthe lambda function to be executed

Definition at line 157 of file ThreadPool.h.

157 : fn_(fn) {}
std::function< void(const StopChecker &)> fn_
Definition: ThreadPool.h:162

◆ LambdaRunner() [2/2]

knowrob::ThreadPool::LambdaRunner::LambdaRunner ( const std::function< void(const StopChecker &)> &  fn)
inlineexplicit
Parameters
fnthe lambda function to be executed

Definition at line 157 of file ThreadPool.h.

157 : fn_(fn) {}

Member Function Documentation

◆ run() [1/2]

void knowrob::ThreadPool::LambdaRunner::run ( )
inlineoverridevirtual

Run the computation in a worker thread.

Implements knowrob::ThreadPool::Runner.

Definition at line 159 of file ThreadPool.h.

159 { fn_([&]{ return hasStopRequest(); }); }

◆ run() [2/2]

void knowrob::ThreadPool::LambdaRunner::run ( )
inlineoverridevirtual

Run the computation in a worker thread.

Implements knowrob::ThreadPool::Runner.

Definition at line 159 of file ThreadPool.h.

159 { fn_([&]{ return hasStopRequest(); }); }

Member Data Documentation

◆ fn_

std::function< void(const StopChecker &)> knowrob::ThreadPool::LambdaRunner::fn_
protected

Definition at line 162 of file ThreadPool.h.


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