The AbstractThread class provides the base functionality for thread management.
More...
#include <AsyncFw/AbstractThread>
|
| enum | PollEvents : uint16_t {
PollNo = 0
, PollIn = POLLIN_
, PollPri = POLLPRI_
, PollOut = POLLOUT_
,
PollErr = POLLERR_
, PollHup = POLLHUP_
, PollNval = POLLNVAL_
} |
| |
|
using | LockGuard = std::lock_guard<std::mutex> |
| | The LockGuard type.
|
| |
|
using | AbstractTask = AbstractFunction<> |
| | The AbstractTask type.
|
| |
|
using | AbstractPollTask = AbstractFunction<AbstractThread::PollEvents> |
| | The AbstractPollTask type.
|
| |
|
| template<typename M> |
| std::enable_if< std::is_void< typenamestd::invoke_result< M >::type >::value, bool >::type | invokeMethod (M method, bool sync=false) const |
| | Runs a method in a managed thread.
|
| |
| template<typename M> |
| bool | appendPollTask (int fd, PollEvents events, M method) |
| | Append poll task.
|
| |
| template<typename M> |
| int | appendTimerTask (int timeout, M method) |
| | Append timer task.
|
| |
| virtual void | startedEvent () |
| | This call from thread when it starts executing.
|
| |
| virtual void | finishedEvent () |
| | This call from the thread when it finishing execution.
|
| |
|
virtual bool | running () const |
| | Returns true if the managed thread is running.
|
| |
| virtual bool | invokeTask (AbstractTask *) const |
| | Runs a task in a managed thread.
|
| |
| virtual int | appendTimer (int, AbstractTask *) |
| | Append timer.
|
| |
| virtual bool | modifyTimer (int, int) |
| | Modify timer.
|
| |
| virtual void | removeTimer (int) |
| | Remove timer.
|
| |
| virtual bool | appendPollDescriptor (int, PollEvents, AbstractPollTask *) |
| | Append poll descriptor.
|
| |
| virtual bool | modifyPollDescriptor (int, PollEvents) |
| | Modify poll descriptor.
|
| |
| virtual void | removePollDescriptor (int) |
| | Remove poll descriptor.
|
| |
|
void | start () |
| | Create a managed thread and run exec().
|
| |
|
void | requestInterrupt () |
| | Request the interruption of the thread.
|
| |
|
bool | interruptRequested () const |
| | Returns true if an interrupt is requested.
|
| |
|
void | waitInterrupted () const |
| | Wait for thread interrupted. This means that requestInterrupt() has been called and all queue tasks have completed.
|
| |
|
void | quit () |
| | Tells the thread's exec() to exit.
|
| |
|
void | waitFinished () const |
| | Wait for the thread's exec() function finished.
|
| |
|
int | workLoad () const |
| | Returns the number of tasks in the queue, plus one if there are running task.
|
| |
|
std::thread::id | id () const |
| | Returns unique identifier of managed thread.
|
| |
|
std::string | name () const |
| | Returns name of managed thread.
|
| |
|
LockGuard | lockGuard () const |
| | Locks the managed thread and returns a LockGuard variable. The thread is unblocked after this variable is destroyed.
|
| |
|
| | AbstractThread (const std::string &) |
| | Constructs a thread.
|
| |
|
void | setId () |
| |
|
void | clearId () |
| |
|
void | exec () |
| | Run manage loop.
|
| |
The AbstractThread class provides the base functionality for thread management.
◆ AbstractThread()
| AbstractThread::AbstractThread |
( |
const std::string & | name | ) |
|
|
protected |
Constructs a thread.
- Parameters
-
◆ invokeMethod()
template<typename M>
| std::enable_if< std::is_void< typenamestd::invoke_result< M >::type >::value, bool >::type AsyncFw::AbstractThread::invokeMethod |
( |
M | method, |
|
|
bool | sync = false ) const |
|
inline |
Runs a method in a managed thread.
- Parameters
-
| method | runs method |
| sync | blocking wait if true |
- Returns
- True if the method is added to the queue
◆ appendPollTask()
template<typename M>
| bool AsyncFw::AbstractThread::appendPollTask |
( |
int | fd, |
|
|
PollEvents | events, |
|
|
M | method ) |
|
inline |
Append poll task.
- Parameters
-
| fd | file descriptor |
| events | watch events |
| method | task method |
- Returns
- True if the task added
◆ appendTimerTask()
template<typename M>
| int AsyncFw::AbstractThread::appendTimerTask |
( |
int | timeout, |
|
|
M | method ) |
|
inline |
Append timer task.
- Parameters
-
| ms | timeout in milliseconds |
| method | task method |
- Returns
- timer id if the task added or value less than zero
◆ threads()
◆ startedEvent()
| void AbstractThread::startedEvent |
( |
| ) |
|
|
virtual |
This call from thread when it starts executing.
Reimplemented in AsyncFw::Thread.
◆ finishedEvent()
| void AbstractThread::finishedEvent |
( |
| ) |
|
|
virtual |
This call from the thread when it finishing execution.
Reimplemented in AsyncFw::Thread.
◆ invokeTask()
| bool AbstractThread::invokeTask |
( |
AbstractTask * | task | ) |
const |
|
virtual |
Runs a task in a managed thread.
- Parameters
-
- Returns
- True if the task is added to the queue
◆ appendTimer()
| int AbstractThread::appendTimer |
( |
int | ms, |
|
|
AbstractTask * | task ) |
|
virtual |
Append timer.
- Parameters
-
- Returns
- timer id if timer added or value less than zero
◆ modifyTimer()
| bool AbstractThread::modifyTimer |
( |
int | id, |
|
|
int | ms ) |
|
virtual |
Modify timer.
- Parameters
-
| id | timer id |
| ms | timeout in milliseconds |
- Returns
- True if the timer modified
◆ removeTimer()
| void AbstractThread::removeTimer |
( |
int | id | ) |
|
|
virtual |
◆ appendPollDescriptor()
| bool AbstractThread::appendPollDescriptor |
( |
int | fd, |
|
|
PollEvents | events, |
|
|
AbstractPollTask * | task ) |
|
virtual |
Append poll descriptor.
- Parameters
-
- Returns
- True if the poll descriptor added
◆ modifyPollDescriptor()
| bool AbstractThread::modifyPollDescriptor |
( |
int | fd, |
|
|
PollEvents | events ) |
|
virtual |
Modify poll descriptor.
- Parameters
-
| fd | file descriptor |
| events | watch events |
- Returns
- True if the poll descriptor modified
◆ removePollDescriptor()
| void AbstractThread::removePollDescriptor |
( |
int | fd | ) |
|
|
virtual |
Remove poll descriptor.
- Parameters
-
The documentation for this class was generated from the following files: