Shaka Packager SDK
|
#include <producer_consumer_queue.h>
Public Member Functions | |
ProducerConsumerQueue (size_t capacity) | |
ProducerConsumerQueue (size_t capacity, size_t starting_pos) | |
Status | Push (const T &element, int64_t timeout_ms) |
Status | Pop (T *element, int64_t timeout_ms) |
Status | Peek (size_t pos, T *element, int64_t timeout_ms) |
void | Stop () |
bool | Empty () const |
size_t | Size () const |
size_t | HeadPos () const |
size_t | TailPos () const |
bool | Stopped () const |
A thread safe producer consumer queue implementation. It allows the standard push and pop operations. It also maintains a monotonically-increasing element position and allows peeking at the element at certain position.
Definition at line 28 of file producer_consumer_queue.h.
|
explicit |
Create a ProducerConsumerQueue starting from position 0.
capacity | is the maximum number of elements that the queue can hold at once. A value of zero means unlimited capacity. |
Definition at line 138 of file producer_consumer_queue.h.
shaka::media::ProducerConsumerQueue< T >::ProducerConsumerQueue | ( | size_t | capacity, |
size_t | starting_pos | ||
) |
Create a ProducerConsumerQueue starting from indicated position.
capacity | is the maximum number of elements that the queue can hold at once. A value of zero means unlimited capacity. |
starting_pos | is the starting head position. |
Definition at line 147 of file producer_consumer_queue.h.
|
inline |
Definition at line 88 of file producer_consumer_queue.h.
|
inline |
Definition at line 101 of file producer_consumer_queue.h.
Status shaka::media::ProducerConsumerQueue< T >::Peek | ( | size_t | pos, |
T * | element, | ||
int64_t | timeout_ms | ||
) |
Peek at the element at the specified position from the queue. If the element is not available yet, block until it to be available or time out or stopped. NOTE: Elements before (pos - capacity/2) will be removed from the queue after Peek operation.
pos | refers to the element position. | |
[out] | element | receives the peeked element. |
timeout_ms | indicates timeout in milliseconds. A value of zero means return immediately. A negative value means waiting indefinitely. |
Definition at line 252 of file producer_consumer_queue.h.
Status shaka::media::ProducerConsumerQueue< T >::Pop | ( | T * | element, |
int64_t | timeout_ms | ||
) |
Pop an element from the front of the queue. If the queue is empty, block for an element to be available to be consumed or time out or stopped.
[out] | element | receives the popped element. |
timeout_ms | indicates timeout in milliseconds. A value of zero means return immediately. A negative value means waiting indefinitely. |
Definition at line 210 of file producer_consumer_queue.h.
Status shaka::media::ProducerConsumerQueue< T >::Push | ( | const T & | element, |
int64_t | timeout_ms | ||
) |
Push an element to the back of the queue. If the queue has reached its capacity limit, block until spare capacity is available or time out or stopped.
element | refers the element to be pushed. |
timeout_ms | indicates timeout in milliseconds. A value of zero means return immediately. A negative value means waiting indefinitely. |
Definition at line 161 of file producer_consumer_queue.h.
|
inline |
Definition at line 94 of file producer_consumer_queue.h.
|
inline |
Terminate Pop and Peek requests once the queue drains entirely. Also terminate all waiting and future Push requests immediately. Stop cannot stall.
Definition at line 79 of file producer_consumer_queue.h.
|
inline |
Definition at line 115 of file producer_consumer_queue.h.
|
inline |
Definition at line 108 of file producer_consumer_queue.h.