Turi Create  4.0
turi::blocking_queue< T > Class Template Reference

Implements a blocking queue useful for producer/consumer models. More...

#include <core/util/blocking_queue.hpp>

Public Member Functions

 blocking_queue ()
 creates a blocking queue
 
void enqueue (const T &elem)
 Add an element to the blocking queue.
 
void enqueue_to_head (const T &elem)
 Add an element to the blocking queue.
 
bool timed_wait_for_data (size_t ns, size_t immediate_size)
 
bool try_timed_wait_for_data (size_t ns, size_t immediate_size)
 
std::pair< T, bool > dequeue ()
 
std::pair< T, bool > try_dequeue ()
 
bool empty ()
 Returns true if the queue is empty.
 
void stop_blocking ()
 
void start_blocking ()
 
size_t size ()
 get the current size of the queue
 
bool wait_until_empty ()
 
void broadcast ()
 
void broadcast_blocking_empty ()
 

Detailed Description

template<typename T>
class turi::blocking_queue< T >

Implements a blocking queue useful for producer/consumer models.

Definition at line 23 of file blocking_queue.hpp.

Member Function Documentation

◆ broadcast()

template<typename T>
void turi::blocking_queue< T >::broadcast ( )
inline

Causes any threads currently blocking on a dequeue to wake up and evaluate the state of the queue. If the queue is empty, the threads will return back to sleep immediately. If the queue is destroyed through stop_blocking, all threads will return.

Definition at line 330 of file blocking_queue.hpp.

◆ broadcast_blocking_empty()

template<typename T>
void turi::blocking_queue< T >::broadcast_blocking_empty ( )
inline

Causes any threads blocking on "wait_until_empty()" to wake up and evaluate the state of the queue. If the queue is not empty, the threads will return back to sleep immediately. If the queue is empty, all threads will return.

Definition at line 344 of file blocking_queue.hpp.

◆ dequeue()

template<typename T>
std::pair<T, bool> turi::blocking_queue< T >::dequeue ( )
inline

Blocks until an element is available in the queue or until stop_blocking() is called. The return value is a pair of <T value, bool success> If "success" if set, then "value" is valid and is an element popped from the queue. If "success" is false, stop_blocking() was called and the queue has been destroyed.

Definition at line 216 of file blocking_queue.hpp.

◆ start_blocking()

template<typename T>
void turi::blocking_queue< T >::start_blocking ( )
inline

Resumes operation of the blocking_queue. Future calls to dequeue will proceed as normal.

Definition at line 292 of file blocking_queue.hpp.

◆ stop_blocking()

template<typename T>
void turi::blocking_queue< T >::stop_blocking ( )
inline

Wakes up all threads waiting on the queue whether or not an element is available. Once this function is called, all existing and future dequeue operations will return with failure. Note that there could be elements remaining in the queue after stop_blocking() is called.

Definition at line 280 of file blocking_queue.hpp.

◆ timed_wait_for_data()

template<typename T>
bool turi::blocking_queue< T >::timed_wait_for_data ( size_t  ns,
size_t  immediate_size 
)
inline

Returns immediately of queue size is >= immedeiate_size Otherwise, it will poll over 'ns' nanoseconds or on a signal until queue is not empty.

Definition at line 141 of file blocking_queue.hpp.

◆ try_dequeue()

template<typename T>
std::pair<T, bool> turi::blocking_queue< T >::try_dequeue ( )
inline

Returns an element if the queue has an entry. returns [item, false] otherwise.

Definition at line 245 of file blocking_queue.hpp.

◆ try_timed_wait_for_data()

template<typename T>
bool turi::blocking_queue< T >::try_timed_wait_for_data ( size_t  ns,
size_t  immediate_size 
)
inline

Returns immediately of queue size is >= immedeiate_size Otherwise, it will poll over 'ns' nanoseconds or on a signal until queue is not empty.

Definition at line 165 of file blocking_queue.hpp.

◆ wait_until_empty()

template<typename T>
bool turi::blocking_queue< T >::wait_until_empty ( )
inline

The conceptual "reverse" of dequeue(). This function will block until the queue becomes empty, or until stop_blocking() is called. Returns true on success. Returns false if the queue is no longer alive

Definition at line 310 of file blocking_queue.hpp.


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