|
BDE 4.39.x Production Release
|
#include <bdlcc_multipriorityqueue.h>
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.
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.
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 |
|
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.
1 <= numPriorities <= 32 (if specified).
|
explicit |
| bdlcc::MultipriorityQueue< TYPE >::~MultipriorityQueue | ( | ) |
Destroy this container.
| bdlcc::MultipriorityQueue< TYPE >::BSLMF_NESTED_TRAIT_DECLARATION | ( | MultipriorityQueue< TYPE > | , |
| bslma::UsesBslmaAllocator | |||
| ) |
|
inline |
Disable pushes to this multipriority queue. This method has no effect unless the queue was enabled.
|
inline |
Enable pushes to this multipriority queue. This method has no effect unless the queue was disabled.
|
inline |
Return true if there are no items in this multi-priority queue, and false otherwise.
|
inline |
Return true if this multipriority queue is enable and false otherwise.
|
inline |
Return the total number of items in this multi-priority queue.
|
inline |
Return the number of distinct priorities (indicated at construction) that are supported by this multi-priority queue.
|
inline |
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.
item is non-null. Note this is unaffected by the enabled / disabled state of the queue. | 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.
0 <= itemPriority < numPriorities(). | 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.
0 <= itemPriority < numPriorities(). | 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.
bdlmt::MultipriorityThreadPool. 0 <= itemPriority < numPriorities(). | 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.
0 <= itemPriority < numPriorities().bdlmt::MultipriorityThreadPool. | void bdlcc::MultipriorityQueue< TYPE >::removeAll | ( | ) |
Remove and destroy all items from this multi-priority queue.
|
inline |
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.
item is non-null. Note this is unaffected by the enabled / disabled state of the queue.