Ocean
Ocean::TaskQueue Class Reference

This class implements a queue for tasks. More...

Inheritance diagram for Ocean::TaskQueue:

Public Types

typedef Caller< void > Task
 Definition of a task as caller function. More...
 

Public Member Functions

void pushTask (const Task &task)
 Adds a new tasks to the queue which will be invoked after all previous task have been invoked. More...
 
size_t pendingTasks ()
 Returns the number of tasks currently in the queue (not counting an currently invoked task). More...
 
void clear ()
 Removes all pending tasks from this queue. More...
 

Protected Types

typedef std::queue< TaskTasks
 Definition of a queue holding tasks. More...
 
- Protected Types inherited from Ocean::Thread
typedef std::pair< pthread_t, bool > TimedJoinPair
 Definition of a pair holding a thread id and a boolean state. More...
 
enum  ThreadPriority {
  PRIORITY_IDLE , PRIORTY_BELOW_NORMAL , PRIORTY_NORMAL , PRIORTY_ABOVE_NORMAL ,
  PRIORTY_HIGH , PRIORTY_REALTIME
}
 Definition of different thread priority values. More...
 

Protected Member Functions

 TaskQueue ()
 Creates a new task queue object. More...
 
 ~TaskQueue ()
 Destructs a task queue object. More...
 
virtual void threadRun ()
 The thread run function. More...
 
- Protected Member Functions inherited from Ocean::Singleton< TaskQueue >
 Singleton ()=default
 Default constructor. More...
 
- Protected Member Functions inherited from Ocean::Thread
 Thread (const Thread &thread)=delete
 Disabled copy constructor. More...
 
void createThread ()
 Creates the thread itself. More...
 
void destroyThread ()
 Destroys the thread itself. More...
 
void stopThreadExplicitly (const unsigned int timeout=5000u)
 Tries to stop the thread gracefully. More...
 
Threadoperator= (const Thread &thread)=delete
 The disabled assign operator. More...
 
 Thread (const std::string &name=std::string())
 Creates a new thread object. More...
 
 Thread (const unsigned int randomNumberSeedValue, const std::string &name=std::string())
 Creates a new thread object. More...
 
virtual ~Thread ()
 Destructs a thread object. More...
 
bool startThread ()
 Starts the thread. More...
 
void stopThread ()
 Informs the thread to stop. More...
 
bool terminateThread ()
 Terminates the thread. More...
 
bool joinThread (const unsigned int timeout=(unsigned int)(-1))
 Waits until this thread has been stopped. More...
 
bool shouldThreadStop () const
 Returns whether this thread should stop. More...
 
bool isThreadInvokedToStart () const
 Returns whether this thread has been invoked to start immediately. More...
 
bool isThreadActive () const
 Returns whether this thread is active. More...
 

Protected Attributes

Tasks queueTasks
 The tasks if this queue. More...
 
bool queueHadTask
 True, if at least one task has been added to this queue before. More...
 
Lock queueLock
 The lock of this queue. More...
 

Friends

class Singleton< TaskQueue >
 

Additional Inherited Members

- Static Public Member Functions inherited from Ocean::Singleton< TaskQueue >
static TaskQueueget ()
 Returns a reference to the unique object. More...
 
- Static Protected Member Functions inherited from Ocean::Thread
static void sleep (unsigned int ms)
 Sleeps the calling thread for a given time. More...
 
static void giveUp ()
 Gives up the remaining thread time. More...
 
static ThreadId currentThreadId ()
 Returns the thread id of the current (calling) thread. More...
 
static ThreadPriority threadPriority ()
 Returns the priority of the current thread. More...
 
static bool setThreadPriority (const ThreadPriority priority)
 Sets the priority of the current thread. More...
 
template<typename TObject , typename TExpectedValue >
static bool waitForValue (TObject &object, const TExpectedValue &expectedValue, const double timeout=-1.0)
 Waits until an object/variable has an expected value. More...
 
template<typename TObject , typename TExpectedValue >
static bool waitForValue (TObject &object, const TExpectedValue &expectedValue, TemporaryScopedLock &temporaryScopedLock, const double timeout=-1.0)
 Waits until an object/variable has an expected value. More...
 
static int pthread_timedjoin_np (pthread_t thread, void **retval, const struct timespec *abstime)
 Implements a thread join function with timeout value. More...
 

Detailed Description

This class implements a queue for tasks.

The queue is based on a single thread so that all tasks will be processes sequential in a normal FIFO queue order.
In contrast to the Scheduler the TaskQueue invokes a function only once.

See also
Scheduler, ThreadPool.

Member Typedef Documentation

◆ Task

Definition of a task as caller function.

◆ Tasks

typedef std::queue<Task> Ocean::TaskQueue::Tasks
protected

Definition of a queue holding tasks.

Constructor & Destructor Documentation

◆ TaskQueue()

Ocean::TaskQueue::TaskQueue ( )
protected

Creates a new task queue object.

◆ ~TaskQueue()

Ocean::TaskQueue::~TaskQueue ( )
protected

Destructs a task queue object.

Member Function Documentation

◆ clear()

void Ocean::TaskQueue::clear ( )

Removes all pending tasks from this queue.

A currently invoked task will not be stopped.

◆ pendingTasks()

size_t Ocean::TaskQueue::pendingTasks ( )

Returns the number of tasks currently in the queue (not counting an currently invoked task).

Returns
The number of pending tasks.

◆ pushTask()

void Ocean::TaskQueue::pushTask ( const Task task)

Adds a new tasks to the queue which will be invoked after all previous task have been invoked.

Parameters
taskThe new task to add

◆ threadRun()

virtual void Ocean::TaskQueue::threadRun ( )
protectedvirtual

The thread run function.

Implements Ocean::Thread.

Friends And Related Function Documentation

◆ Singleton< TaskQueue >

friend class Singleton< TaskQueue >
friend

Field Documentation

◆ queueHadTask

bool Ocean::TaskQueue::queueHadTask
protected

True, if at least one task has been added to this queue before.

◆ queueLock

Lock Ocean::TaskQueue::queueLock
protected

The lock of this queue.

◆ queueTasks

Tasks Ocean::TaskQueue::queueTasks
protected

The tasks if this queue.


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