Quick Links:

bal | bbl | bdl | bsl

Public Member Functions

bdlcc::MultipriorityQueue< TYPE > Class Template Reference

#include <bdlcc_multipriorityqueue.h>

List of all members.

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (MultipriorityQueue, bslma::UsesBslmaAllocator)
 MultipriorityQueue (bslma::Allocator *basicAllocator=0)
 MultipriorityQueue (int numPriorities, bslma::Allocator *basicAllocator=0)
 ~MultipriorityQueue ()
void popFront (TYPE *item, int *itemPriority=0)
int pushBack (const TYPE &item, int itemPriority)
int pushBack (bslmf::MovableRef< TYPE > item, int itemPriority)
void pushBackMultipleRaw (const TYPE &item, int itemPriority, int numItems)
void pushFrontMultipleRaw (const TYPE &item, int itemPriority, int numItems)
int tryPopFront (TYPE *item, int *itemPriority=0)
void removeAll ()
void enable ()
void disable ()
int numPriorities () const
int length () const
bool isEmpty () const
bool isEnabled () const

Detailed Description

template<class TYPE>
class bdlcc::MultipriorityQueue< TYPE >

This class implements a thread-enabled multipriority queue whose priorities are restricted to a (small) set of contiguous N integer values, [ 0 .. N - 1 ], with 0 being the most urgent.

This class does have a notion of value, namely the sequence of priority/element pairs, constrained to be in decreasing order of urgency (i.e., monotonically increasing priority values). However, no value-semantic operations are implemented. Note that elements having the same priority are maintained in First-In-First-Out (FIFO) order. Note that the current implementation supports up to a maximum of sizeof(int) * CHAR_BIT priorities.

This class is implemented as a set of linked lists, one for each priority. Two vectors are used to maintain head and tail pointers for the lists.

See Component bdlcc_multipriorityqueue


Constructor & Destructor Documentation

template<class TYPE>
bdlcc::MultipriorityQueue< TYPE >::MultipriorityQueue ( bslma::Allocator basicAllocator = 0  )  [explicit]
template<class TYPE>
bdlcc::MultipriorityQueue< TYPE >::MultipriorityQueue ( int  numPriorities,
bslma::Allocator basicAllocator = 0 
) [explicit]

Create a multipriority queue. Optionally specify numPriorities, the number of distinct priorities supported by the multipriority queue. If numPriorities is not specified, the (implementation-imposed maximum) number 32 is used. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used. The behavior is undefined unless 1 <= numPriorities <= 32 (if specified).

template<class TYPE>
bdlcc::MultipriorityQueue< TYPE >::~MultipriorityQueue (  ) 

Destroy this container. The behavior is undefined unless all access or modification of the container has completed prior to this call.


Member Function Documentation

template<class TYPE>
bdlcc::MultipriorityQueue< TYPE >::BSLMF_NESTED_TRAIT_DECLARATION ( MultipriorityQueue< TYPE >  ,
bslma::UsesBslmaAllocator   
)
template<class TYPE>
void bdlcc::MultipriorityQueue< TYPE >::popFront ( TYPE *  item,
int *  itemPriority = 0 
)

Remove the least-recently added item having the most urgent priority (lowest value) from this multi-priority queue and load its value into the specified item. If this queue is empty, this method blocks the calling thread until an item becomes available. If the optionally specified itemPriority is non-null, load the priority of the popped item into itemPriority. The behavior is undefined unless item is non-null. Note this is unaffected by the enabled / disabled state of the queue.

template<class TYPE>
int bdlcc::MultipriorityQueue< TYPE >::pushBack ( const TYPE &  item,
int  itemPriority 
)

Insert the value of the specified item with the specified itemPriority into this multipriority queue before any queued items having a less urgent priority (higher value) than itemPriority, and after any items having the same or more urgent priority (lower value) than itemPriority. If the multipriority queue is enabled, the push succeeds and 0 is returned, otherwise the push fails, the queue remains unchanged, and a nonzero value is returned. The behavior is undefined unless 0 <= itemPriority < numPriorities().

template<class TYPE>
int bdlcc::MultipriorityQueue< TYPE >::pushBack ( bslmf::MovableRef< TYPE >  item,
int  itemPriority 
)

Insert the value of the specified item with the specified itemPriority into this multipriority queue before any queued items having a less urgent priority (higher value) than itemPriority, and after any items having the same or more urgent priority (lower value) than itemPriority. item is left in a valid but unspecified state. If the multipriority queue is enabled, the push succeeds and 0 is returned, otherwise the push fails, the queue remains unchanged, and a nonzero value is returned. The behavior is undefined unless 0 <= itemPriority < numPriorities().

template<class TYPE>
void bdlcc::MultipriorityQueue< TYPE >::pushBackMultipleRaw ( const TYPE &  item,
int  itemPriority,
int  numItems 
)

Insert the value of the specified item with the specified itemPriority onto the back of this multipriority queue before any queued items having a less urgent priority (higher value) than itemPriority, and after any items having the same or more urgent priority (lower value) than itemPriority. All of the specified numItems items are pushed as a single atomic action, unless the copy constructor for one of them throws an exception, in which case a possibly empty subset of the pushes will have completed and no memory will be leaked. Raw means that the push will succeed even if the multipriority queue is disabled. Note that this method is targeted for specific use by the class bdlmt::MultipriorityThreadPool. The behavior is undefined unless 0 <= itemPriority < numPriorities().

template<class TYPE>
void bdlcc::MultipriorityQueue< TYPE >::pushFrontMultipleRaw ( const TYPE &  item,
int  itemPriority,
int  numItems 
)

Insert the value of the specified item with the specified itemPriority into the front of this multipriority queue the specified numItems times, before any queued items having the same or less urgent priority (higher value) than itemPriority, and after any items having more urgent priority (lower value) than itemPriority. All numItems items are pushed as a single atomic action, unless the copy constructor throws while creating one of them, in which case a possibly empty subset of the pushes will have completed and no memory will be leaked. Raw means that the push will succeed even if the multipriority queue is disabled. The behavior is undefined unless 0 <= itemPriority < numPriorities(). Note that this method is targeted at specific uses by the class bdlmt::MultipriorityThreadPool.

template<class TYPE>
int bdlcc::MultipriorityQueue< TYPE >::tryPopFront ( TYPE *  item,
int *  itemPriority = 0 
)

Attempt to remove (immediately) the least-recently added item having the most urgent priority (lowest value) from this multi-priority queue. On success, load the value of the popped item into the specified item; if the optionally specified itemPriority is non-null, load the priority of the popped item into itemPriority; and return 0. Otherwise, leave item and itemPriority unmodified, and return a non-zero value indicating that this queue was empty. The behavior is undefined unless item is non-null. Note this is unaffected by the enabled / disabled state of the queue.

template<class TYPE>
void bdlcc::MultipriorityQueue< TYPE >::removeAll (  ) 

Remove and destroy all items from this multi-priority queue.

template<class TYPE>
void bdlcc::MultipriorityQueue< TYPE >::enable (  ) 

Enable pushes to this multipriority queue. This method has no effect unless the queue was disabled.

template<class TYPE>
void bdlcc::MultipriorityQueue< TYPE >::disable (  ) 

Disable pushes to this multipriority queue. This method has no effect unless the queue was enabled.

template<class TYPE>
int bdlcc::MultipriorityQueue< TYPE >::numPriorities (  )  const

Return the number of distinct priorities (indicated at construction) that are supported by this multi-priority queue.

template<class TYPE>
int bdlcc::MultipriorityQueue< TYPE >::length (  )  const

Return the total number of items in this multi-priority queue.

template<class TYPE>
bool bdlcc::MultipriorityQueue< TYPE >::isEmpty (  )  const

Return true if there are no items in this multi-priority queue, and false otherwise.

template<class TYPE>
bool bdlcc::MultipriorityQueue< TYPE >::isEnabled (  )  const

Return true if this multipriority queue is enable and false otherwise.


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