ONPOSIX  2.0
 All Classes Namespaces Files Functions Variables Enumerator Friends Macros Pages
PosixDescriptor::shared_queue Class Reference

Class for synchronization between the main thread and the worker thread. More...

Public Member Functions

 shared_queue ()
 Constructor.
void push (struct job *j)
 Add an asynchronous operation.
void signal_not_empty ()
 Signal the worker that there are new operations.
void signal_empty ()
 Signal the main thread that the queue is empty.
void wait_not_empty ()
 Wait until there are new operations.
void wait_empty ()
 Wait until the queue is empty.
void set_flush_and_close ()
 Signal that the descriptor is going to be close.
jobpop (bool *close)
 Pop the next operation from the queue.

Private Attributes

std::queue< job * > queue_
 Queue of all pending operations.
bool flush_and_close_
 Signal the worker to not block anymore.
PosixMutex lock_
 Mutex to avoid contentions.
PosixCondition cond_not_empty_
 Condition for not empty queue.
PosixCondition cond_empty_
 Condition for empty queue.

Detailed Description

Class for synchronization between the main thread and the worker thread.

This data structure is in charge of keeping a queue of pending asynchronous operations (shared between the main thread and the worker thread) and synchronize the two threads.

Definition at line 110 of file PosixDescriptor.hpp.

Constructor & Destructor Documentation

shared_queue ( )
inline

Constructor.

Definition at line 153 of file PosixDescriptor.hpp.

: flush_and_close_(false) {}

Member Function Documentation

job* pop ( bool *  close)
inline

Pop the next operation from the queue.

This method is used by the worker to pop the next operation from the queue.

Parameters
closePointer to a boolean used as return variable to tell the worker if the descriptor is going to be closed.
Returns
pointer to a job instance allocated in the heap; 0 if the queue is empty.

Definition at line 240 of file PosixDescriptor.hpp.

{
job* ret = 0;
if (!queue_.empty()){
ret = queue_.front();
queue_.pop();
}
if (queue_.empty()){
}
return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void push ( struct job j)
inline

Add an asynchronous operation.

Parameters
jasynchronous operation

Definition at line 160 of file PosixDescriptor.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void set_flush_and_close ( )
inline

Signal that the descriptor is going to be close.

This method is used to let the main thread signal the worker that the descriptor is going to be closed, so it must flush all pending operations and not block on wait_not_empty() anymore.

Definition at line 224 of file PosixDescriptor.hpp.

{
}

Here is the call graph for this function:

Here is the caller graph for this function:

void signal_empty ( )
inline

Signal the main thread that the queue is empty.

This method is used by the worker to signal the main thread that the queue is empty and all pending operations have been carried out.

Definition at line 186 of file PosixDescriptor.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void signal_not_empty ( )
inline

Signal the worker that there are new operations.

This method is used by the main thread to signal the worker that there are new operations in the queue.

Definition at line 173 of file PosixDescriptor.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void wait_empty ( )
inline

Wait until the queue is empty.

This method is used by the main thread to wait until the queue is empty to close the descriptor.

Definition at line 210 of file PosixDescriptor.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void wait_not_empty ( )
inline

Wait until there are new operations.

This method is used by the worker to wait until there are new operations in the queue.

Definition at line 198 of file PosixDescriptor.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

PosixCondition cond_empty_
private

Condition for empty queue.

This condition signals the main thread that the queue is empty. Used by the worker thread to signal the main thread when the descriptor is going to be closed.

Definition at line 149 of file PosixDescriptor.hpp.

PosixCondition cond_not_empty_
private

Condition for not empty queue.

This condition signals the worker thread that there is work to be carried out (i.e., the queue is not empty).

Definition at line 140 of file PosixDescriptor.hpp.

bool flush_and_close_
private

Signal the worker to not block anymore.

This variable signals the worker thread that must flush all pending operations and not block on the condition variable because the descriptor is going to be closed.

Definition at line 124 of file PosixDescriptor.hpp.

PosixMutex lock_
private

Mutex to avoid contentions.

This mutex protects accesses to queue_ and flush_and_close_ when asynchronous operations are scheduled.

Definition at line 132 of file PosixDescriptor.hpp.

std::queue<job*> queue_
private

Queue of all pending operations.

Definition at line 115 of file PosixDescriptor.hpp.


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