AsyncFw 1.2
Async Framework is c++ runtime with timers, poll notifiers, sockets, coroutines, etc.
 
Loading...
Searching...
No Matches
AsyncFw::AbstractThread Class Referenceabstract

The AbstractThread class provides the base functionality for thread management. More...

#include <AsyncFw/AbstractThread>

Inheritance diagram for AsyncFw::AbstractThread:
[legend]

Classes

class  Holder
 The Holder class. More...
 

Public Types

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.
 

Public Member Functions

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.
 

Static Public Member Functions

static AbstractThreadcurrentThread ()
 Returns a pointer to the AsyncFw::AbstractThread that manages the currently executing thread.
 
static AbstractThread::LockGuard threads (std::vector< AbstractThread * > **)
 Assigns a pointer to the list of all threads.
 

Protected Member Functions

 AbstractThread (const std::string &)
 Constructs a thread.
 
void setId ()
 
void clearId ()
 
void exec ()
 Run manage loop.
 

Friends

class Thread
 
LogStreamoperator<< (LogStream &log, const AbstractThread &t)
 

Detailed Description

The AbstractThread class provides the base functionality for thread management.

Constructor & Destructor Documentation

◆ AbstractThread()

AbstractThread::AbstractThread ( const std::string & name)
protected

Constructs a thread.

Parameters
namethread name
Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ 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
methodruns method
syncblocking wait if true
Returns
True if the method is added to the queue
Here is the call graph for this function:

◆ appendPollTask()

template<typename M>
bool AsyncFw::AbstractThread::appendPollTask ( int fd,
PollEvents events,
M method )
inline

Append poll task.

Parameters
fdfile descriptor
eventswatch events
methodtask method
Returns
True if the task added
Here is the call graph for this function:

◆ appendTimerTask()

template<typename M>
int AsyncFw::AbstractThread::appendTimerTask ( int timeout,
M method )
inline

Append timer task.

Parameters
mstimeout in milliseconds
methodtask method
Returns
timer id if the task added or value less than zero
Here is the call graph for this function:

◆ threads()

AbstractThread::LockGuard AbstractThread::threads ( std::vector< AbstractThread * > ** list)
static

Assigns a pointer to the list of all threads.

Parameters
listpointer to the list of threads
Returns
AbstractThread::LockGuard

◆ startedEvent()

void AbstractThread::startedEvent ( )
virtual

This call from thread when it starts executing.

Reimplemented in AsyncFw::Thread.

Here is the caller graph for this function:

◆ finishedEvent()

void AbstractThread::finishedEvent ( )
virtual

This call from the thread when it finishing execution.

Reimplemented in AsyncFw::Thread.

Here is the caller graph for this function:

◆ invokeTask()

bool AbstractThread::invokeTask ( AbstractTask * task) const
virtual

Runs a task in a managed thread.

Parameters
taskpoiner to AbstractTask
Returns
True if the task is added to the queue
Here is the caller graph for this function:

◆ appendTimer()

int AbstractThread::appendTimer ( int ms,
AbstractTask * task )
virtual

Append timer.

Parameters
mstimeout in milliseconds
taskpointer to AbstractTask
Returns
timer id if timer added or value less than zero
Here is the call graph for this function:
Here is the caller graph for this function:

◆ modifyTimer()

bool AbstractThread::modifyTimer ( int id,
int ms )
virtual

Modify timer.

Parameters
idtimer id
mstimeout in milliseconds
Returns
True if the timer modified

◆ removeTimer()

void AbstractThread::removeTimer ( int id)
virtual

Remove timer.

Parameters
idtimer id
Here is the call graph for this function:

◆ appendPollDescriptor()

bool AbstractThread::appendPollDescriptor ( int fd,
PollEvents events,
AbstractPollTask * task )
virtual

Append poll descriptor.

Parameters
fdfile descriptor
eventswatch events
taskpointer to AbstractPollTask
Returns
True if the poll descriptor added
Here is the caller graph for this function:

◆ modifyPollDescriptor()

bool AbstractThread::modifyPollDescriptor ( int fd,
PollEvents events )
virtual

Modify poll descriptor.

Parameters
fdfile descriptor
eventswatch events
Returns
True if the poll descriptor modified

◆ removePollDescriptor()

void AbstractThread::removePollDescriptor ( int fd)
virtual

Remove poll descriptor.

Parameters
fdfile descriptor
Here is the call graph for this function:

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