This class implements a simple thread-safe queue for communication among threads.
More...
#include <Queue.h>
|
| Queue (int=10) |
|
bool | init () |
|
void | reset () |
| Reset the queue, discarding any contents. More...
|
|
bool | empty () const |
| Determine if queue is empty. More...
|
|
void | enq (int) |
| Add value to the end of the queue. More...
|
|
int | deq () |
| Remove and return first item in the queue. More...
|
|
int | deq (uint32_t) |
| Remove and return first item in the queue, with timeout. More...
|
|
|
static int const | TIMEOUT = (1 << 31) |
|
|
int | qMax |
| max number of items in queue
|
|
int | count |
| number of items in queue
|
|
int | head |
| index of first item in buf
|
|
int | tail |
| index of first empty space in buf
|
|
int * | buf |
| where values are stored
|
|
pthread_mutex_t | lock |
| used to ensure mutual exclusion
|
|
pthread_cond_t | emptyQ |
| condition variable for empty queue
|
|
pthread_cond_t | fullQ |
| condition variable for full queue
|
|
This class implements a simple thread-safe queue for communication among threads.
Definition at line 22 of file Queue.h.
int forest::Queue::deq |
( |
) | |
|
Remove and return first item in the queue.
The calling thread is blocked if the queue is empty.
- Returns
- the next item in the queue
Definition at line 67 of file Queue.cpp.
int forest::Queue::deq |
( |
uint32_t |
timeout) | |
|
Remove and return first item in the queue, with timeout.
The calling thread is blocked if the queue is empty, but the method returns early if the specified timeout expires.
- Parameters
-
timeout | is the number of nanoseconds after which the method should return, even if nothing has been added to the queue. |
- Returns
- the next item in the queue, or Queue::TIMEOUT if timeout occurs
Definition at line 89 of file Queue.cpp.
bool forest::Queue::empty |
( |
) | |
const |
|
inline |
Determine if queue is empty.
- Returns
- true if the queue is empty, else false
Definition at line 51 of file Queue.h.
void forest::Queue::enq |
( |
int |
i) | |
|
Add value to the end of the queue.
The calling thread is blocked if the queue is full.
- Parameters
-
i | is the value to be added. |
Definition at line 48 of file Queue.cpp.
void forest::Queue::reset |
( |
) | |
|
Reset the queue, discarding any contents.
This must only be used by the single writer to the queue;
Definition at line 30 of file Queue.cpp.
The documentation for this class was generated from the following files: