Dataflow Runtime API  4.0.1.0
Public Member Functions | List of all members
imt::base::os::linux::Thread Class Referencefinal

Provides a thread instance toghether with the infrastructure required to stop the thread as well as some synchronization primitives that can be used to synchronize access to shared data. More...

#include <Imt.Base.OS.Linux/Thread.h>

Public Member Functions

 Thread (std::string const &threadName, ThreadSchedulingParams schedulingParams, std::function< void()> threadFunction) noexcept
 Constructor. More...
 
 ~Thread ()
 Destructor. More...
 
void start ()
 Starts execution of the thread. More...
 
void stop () noexcept
 Stops execution of the thread. More...
 
bool isStopRequested () const noexcept
 Gets whether a stop of the thread is requested. More...
 
constexpr std::mutex & getMutex () noexcept
 Gets the mutex associated with this thread. More...
 
constexpr std::condition_variable & getConditionVariable () noexcept
 Gets the condition variable associated with this thread. More...
 
constexpr std::string const & getName () const noexcept
 Gets the name of this thread. More...
 
void waitFor (std::chrono::milliseconds const waitTimeMs)
 Lets the current thread wait for the condition variable beeing set or the waitTimeMs to elapse. More...
 
 Thread (Thread const &source)=delete
 
 Thread (Thread &&source) noexcept=delete
 
Threadoperator= (Thread const &source)=delete
 
Threadoperator= (Thread &&source) noexcept=delete
 

Detailed Description

Provides a thread instance toghether with the infrastructure required to stop the thread as well as some synchronization primitives that can be used to synchronize access to shared data.

The synchronization primitives - especially the std::condition_variable - is provided by this thread to support waiting for conditions that take the request to stop the whole thread into account. Unfortunately the the posix like conditions don't support waiting for multiple conditions like the windows WaitFor.. functions. Therefore, we have to provide one condition that is set when a stop is requested (internally by this implementaiton). Users of the thread will also set the very same condition when e.g. new data is available for processing, causing the thread to wakeup and continue execution.

Constructor & Destructor Documentation

◆ Thread() [1/3]

imt::base::os::linux::Thread::Thread ( std::string const &  threadName,
ThreadSchedulingParams  schedulingParams,
std::function< void()>  threadFunction 
)
noexcept

Constructor.

Parameters
threadNameThe name associated with the thread
schedulingParamsThe scheduling parameters applied for the thread
threadFunctionThe function executed by the thread

◆ ~Thread()

imt::base::os::linux::Thread::~Thread ( )

Destructor.

◆ Thread() [2/3]

imt::base::os::linux::Thread::Thread ( Thread const &  source)
delete

◆ Thread() [3/3]

imt::base::os::linux::Thread::Thread ( Thread &&  source)
deletenoexcept

Member Function Documentation

◆ getConditionVariable()

constexpr std::condition_variable& imt::base::os::linux::Thread::getConditionVariable ( )
inlineconstexprnoexcept

Gets the condition variable associated with this thread.

Returns
The condition variable associated with this thread

◆ getMutex()

constexpr std::mutex& imt::base::os::linux::Thread::getMutex ( )
inlineconstexprnoexcept

Gets the mutex associated with this thread.

Returns
The mutex associated with this thread

◆ getName()

constexpr std::string const& imt::base::os::linux::Thread::getName ( ) const
inlineconstexprnoexcept

Gets the name of this thread.

◆ isStopRequested()

bool imt::base::os::linux::Thread::isStopRequested ( ) const
noexcept

Gets whether a stop of the thread is requested.

◆ operator=() [1/2]

Thread& imt::base::os::linux::Thread::operator= ( Thread &&  source)
deletenoexcept

◆ operator=() [2/2]

Thread& imt::base::os::linux::Thread::operator= ( Thread const &  source)
delete

◆ start()

void imt::base::os::linux::Thread::start ( )

Starts execution of the thread.

◆ stop()

void imt::base::os::linux::Thread::stop ( )
noexcept

Stops execution of the thread.

◆ waitFor()

void imt::base::os::linux::Thread::waitFor ( std::chrono::milliseconds const  waitTimeMs)

Lets the current thread wait for the condition variable beeing set or the waitTimeMs to elapse.

Parameters
waitTimeMsThe wait time in milliseconds

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