pc_priority_queue


An os_pc_priority_queue is a priority based producer consumer queue with a specified maximum size (bounded buffer). Items can be inserted into the queue using the push() method. If the queue is full, the calling thread blocks until the queue is not full. Items can be removed from the queue in the order of priority using the pop() method. If the queue is empty, the calling thread blocks until the queue is not empty.

The template arguments of the os_pc_priority_queue class are similar to the C++ standard library priority_queue container adapter class.

Library

Thread<ToolKit>

Declaration

#include <ospace/thread/priqueue.h>

template< class T, class Container, class Compare >
class os_pc_priority_queue

Interface

Constructor
os_pc_priority_queue( size_type max_size )
Constructs a priority queue with a maximum size limit of max_size and a default constructed object of type Container as the internal buffer. A default constructed object of type Compare is used as the comparison object.
Constructor
os_pc_priority_queue( size_type max_size , const Compare& compare )
Constructs a priority queue with a maximum size limit of max_size and a default constructed object of type Container as the internal buffer. A copy of compare is used as the comparison object.
Constructor
os_pc_priority_queue( size_type max_size , const Compare& compare , const Container& container )
Constructs a priority queue with a maximum size limit of max_size and a copy of container as the internal buffer. A copy of compare is used by comparator object.
Destructor
~os_pc_priority_queue()
Destroys the priority queue.
<
bool operator<( const os_pc_priority_queue< T, Container, Compare >& other ) const
Returns true if this queue is lexicographically less than other .
==
bool operator==( const os_pc_priority_queue< T, Container, Compare >& other ) const
Returns true if this queue and other are equivalent.
close
void close()
Closes the queue. No items will be allowed to be pushed into the queue. Items will be allowed to be popped until the queue becomes empty.
closed
bool closed() const
Returns true if closed for adding new items. All threads calling pop() will not block.
empty
bool empty() const
Returns true if the queue contain no elements.
full
bool full() const
Returns true if the queue is full.
max_size
size_type max_size() const
Returns the maximum number of elements the queue can contain.
pop
value_type pop()
Removes the item in the front of the queue (sorted order) and returns it. If the queue is empty, the calling thread blocks until the queue is not empty. If this method is called after the queue is closed, then an exception is thrown.

Throws: os_thread_toolkit_error

pop
void pop( value_type& value )
Removes the item in the front of the queue (sorted order) and places a copy of it in value . If the queue is empty, the calling thread blocks until the queue is not empty. If this method is called after the queue is closed, then an exception is thrown.

Throws: os_thread_toolkit_error

pop
bool pop( value_type& value , long milliseconds )
Removes the item in the front of the queue (sorted order) and places a copy of it in value . If the queue is empty, the calling thread blocks until the queue is not empty or until milliseconds time expires. Returns true if the value is filled with the popped value. If this method is called after the queue is closed, then an exception is thrown.

Throws: os_thread_toolkit_error

push
void push( const value_type& value )
Inserts the item value into the queue. If the queue is full, the calling thread blocks until the queue is not full. Items in the queue are maintained in a sort order. If this method is called after the queue is closed, then an exception is thrown.

Throws: os_thread_toolkit_error

push
bool push( const value_type& value , long milliseconds )
Inserts the item value into the queue. If the queue is full, the calling thread blocks until the queue is not full or until milliseconds time expires. Items in the queue are maintained in a sort order. Returns true if the value is inserted. If this method is called after the queue is closed, then an exception is thrown.

Throws: os_thread_toolkit_error

reopen
void reopen()
Reopens the queue for pushing and popping items.
size
size_type size() const
Returns the number of elements that the queue currently contains.

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.