osmium::thread::SortedQueue< T > Class Template Reference

`#include <sorted_queue.hpp>`

## Public Member Functions

| SortedQueue ()
void | push (T value, size_type num)
void | wait_and_pop (T &value)
bool | try_pop (T &value)
bool | empty () const
size_t | size () const

## Private Types

typedef std::deque< T >::size_type | size_type

## Private Member Functions

bool | empty_intern () const

## Private Attributes

std::mutex | m_mutex
std::deque< T > | m_queue
std::condition_variable | m_data_available
size_type | m_offset

## Detailed Description

### template<typename T>
class osmium::thread::SortedQueue< T >

This implements a sorted queue. It is a bit like a priority queue. We have n worker threads pushing items into the queue and one thread pulling them out again "in order". The order is defined by the monotonically increasing "num" parameter to the push() method. The wait_and_pop() and try_pop() methods will only give out the next numbered item. This way several workers can work in their own time on different pieces of some incoming data, but it all gets serialized properly again after the workers have done their work.

## Member Typedef Documentation

template<typename T >

typedef std::deque<T>::size_type osmium::thread::SortedQueue< T >::size_type

private

## Constructor & Destructor Documentation

template<typename T >

osmium::thread::SortedQueue< T >::SortedQueue | ( |  | ) |

inline

## Member Function Documentation

template<typename T >

bool osmium::thread::SortedQueue< T >::empty | ( |  | ) | const

inline

The queue is empty. This means try_pop() would fail if called. It does not mean that there is nothing on the queue. Because the queue is sorted, it could mean that the next item in the queue is not available, but other items are.

template<typename T >

bool osmium::thread::SortedQueue< T >::empty_intern | ( |  | ) | const

inline private

template<typename T >

void osmium::thread::SortedQueue< T >::push | ( | T | value,
|  | size_type | num
| ) |  |

inline

Push an item into the queue.

Parameters

  value | The item to push into the queue.
  num | Number to describe ordering for the items. It must increase monotonically.

template<typename T >

size_t osmium::thread::SortedQueue< T >::size | ( |  | ) | const

inline

Returns the number of items in the queue, regardless of whether they can be accessed. If this is =0 it implies empty()==true, but not the other way around.

template<typename T >

bool osmium::thread::SortedQueue< T >::try_pop | ( | T & | value | ) |

inline

Get next item if it is available and return true. Or return false otherwise.

template<typename T >

void osmium::thread::SortedQueue< T >::wait_and_pop | ( | T & | value | ) |

inline

Wait until the next item becomes available and make it available through value.

## Member Data Documentation

template<typename T >

std::condition_variable osmium::thread::SortedQueue< T >::m_data_available

private

template<typename T >

std::mutex osmium::thread::SortedQueue< T >::m_mutex

mutable private

template<typename T >

size_type osmium::thread::SortedQueue< T >::m_offset

private

template<typename T >

std::deque<T> osmium::thread::SortedQueue< T >::m_queue

private

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

- osmium/thread/sorted_queue.hpp