GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
graphlab::blocking_queue< T > Class Template Reference

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

#include <graphlab/util/blocking_queue.hpp>

List of all members.

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.
void enqueue_conditional_signal (const T &elem, size_t signal_at_size)
bool empty_unsafe ()
void begin_critical_section ()
bool is_alive ()
void swap (queue_type &q)
std::pair< T, bool > try_dequeue_in_critical_section ()
void end_critical_section ()
std::pair< T, bool > dequeue_and_begin_critical_section_on_success ()
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)
bool wait_for_data ()
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 ()

Protected Types

typedef std::deque< T > queue_type

Protected Attributes

bool m_alive
queue_type m_queue
mutex m_mutex
conditional m_conditional
conditional m_empty_conditional
volatile uint16_t sleeping
volatile uint16_t sleeping_on_empty

Detailed Description

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

Implements a blocking queue useful for producer/consumer models.

Definition at line 42 of file blocking_queue.hpp.


Member Function Documentation

template<typename T>
void graphlab::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 352 of file blocking_queue.hpp.

template<typename T>
void graphlab::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 366 of file blocking_queue.hpp.

template<typename T>
std::pair<T, bool> graphlab::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 235 of file blocking_queue.hpp.

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

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

Definition at line 311 of file blocking_queue.hpp.

template<typename T>
void graphlab::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 299 of file blocking_queue.hpp.

template<typename T>
bool graphlab::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 160 of file blocking_queue.hpp.

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

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

Definition at line 264 of file blocking_queue.hpp.

template<typename T>
bool graphlab::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 184 of file blocking_queue.hpp.

template<typename T>
bool graphlab::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 332 of file blocking_queue.hpp.


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