ONPOSIX
2.0
|
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. | |
job * | pop (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. |
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.
|
inline |
|
inline |
Pop the next operation from the queue.
This method is used by the worker to pop the next operation from the queue.
close | Pointer to a boolean used as return variable to tell the worker if the descriptor is going to be closed. |
Definition at line 240 of file PosixDescriptor.hpp.
|
inline |
Add an asynchronous operation.
j | asynchronous operation |
Definition at line 160 of file PosixDescriptor.hpp.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
private |
Queue of all pending operations.
Definition at line 115 of file PosixDescriptor.hpp.