Libosmium
2.6.1
Fast and flexible C++ library for working with OpenStreetMap data
|
#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 |
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.
|
private |
|
inline |
|
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.
|
inlineprivate |
|
inline |
Push an item into the queue.
value | The item to push into the queue. |
num | Number to describe ordering for the items. It must increase monotonically. |
|
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.
|
inline |
Get next item if it is available and return true. Or return false otherwise.
|
inline |
Wait until the next item becomes available and make it available through value.
|
private |
|
mutableprivate |
|
private |
|
private |