CppELib 1.7.0
Loading...
Searching...
No Matches
OSWrapper::ThreadPool::WaitGuard Class Reference

Class to wait for the asynchronous task finished. More...

#include <ThreadPool.h>

Public Member Functions

 WaitGuard ()
 Constructor of WaitGuard.
 
 ~WaitGuard ()
 Destructor of WaitGuard.
 
void release ()
 Call wait(), release the resource, and turn the valid state to invalid.
 
Error wait ()
 Block the current thread until the asynchronous task finished.
 
Error tryWait ()
 Query without blocking whether the asynchronous task finished.
 
Error timedWait (Timeout tmout)
 Block the current thread until the asynchronous task finished but only within the limited time.
 
bool isValid () const
 Return true if the validity state is valid.
 

Detailed Description

Class to wait for the asynchronous task finished.

WaitGuard has a validity state, valid or invalid. After constuction, the state is invalid. The state becomes valid by ThreadPool::start(), ThreadPool::tryStart(), or ThreadPool::timedStart(). If the state is valid, the thread that owns this WaitGuard must wait() until the started asynchronous task finished and must release() the WaitGuard. After release(), the state becomes invalid.

WaitGuard can't be copied.

Constructor & Destructor Documentation

◆ WaitGuard()

OSWrapper::ThreadPool::WaitGuard::WaitGuard ( )

Constructor of WaitGuard.

Postcondition
isValid() == false

◆ ~WaitGuard()

OSWrapper::ThreadPool::WaitGuard::~WaitGuard ( )

Destructor of WaitGuard.

Destructor calls release() if the validity state is valid.

Member Function Documentation

◆ isValid()

bool OSWrapper::ThreadPool::WaitGuard::isValid ( ) const

Return true if the validity state is valid.

Return values
trueThe state is valid
falseThe state is invalid

◆ release()

void OSWrapper::ThreadPool::WaitGuard::release ( )

Call wait(), release the resource, and turn the valid state to invalid.

Postcondition
isValid() == false
Note
If the state is invalid, this method does nothing.

◆ timedWait()

Error OSWrapper::ThreadPool::WaitGuard::timedWait ( Timeout  tmout)

Block the current thread until the asynchronous task finished but only within the limited time.

Parameters
tmoutThe limited time
Return values
OKSuccess. The asynchronous task has finished
TimedOutThe limited time was elapsed
CalledByNonThreadCalled from non thread context (interrupt handler, timer, etc)
Note
If the state is invalid, this method returns OK immediately.
If tmout is Timeout::POLLING then this method queries the state without blocking.
If tmout is Timeout::FOREVER then this method waits forever until the condition is satisfied.

◆ tryWait()

Error OSWrapper::ThreadPool::WaitGuard::tryWait ( )

Query without blocking whether the asynchronous task finished.

Return values
OKThe asynchronous task has already finished
TimedOutThe asynchronous task has not finished yet
Note
If the state is invalid, this method returns OK immediately.
Same as timedWait(Timeout::POLLING)

◆ wait()

Error OSWrapper::ThreadPool::WaitGuard::wait ( )

Block the current thread until the asynchronous task finished.

Return values
OKSuccess. The asynchronous task has finished
CalledByNonThreadCalled from non thread context (interrupt handler, timer, etc)
Note
If the state is invalid, this method returns OK immediately.
Same as timedWait(Timeout::FOREVER)

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