8#ifndef INCLUDED_BDLCC_MULTIPRIORITYQUEUE
9#define INCLUDED_BDLCC_MULTIPRIORITYQUEUE
444#include <bdlscm_version.h>
469#include <bsl_climits.h>
470#include <bsl_cstdint.h>
472#include <bsl_vector.h>
474#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
570 k_BITS_PER_INT =
sizeof(int) * CHAR_BIT,
571 k_DEFAULT_NUM_PRIORITIES = k_BITS_PER_INT,
572 k_MAX_NUM_PRIORITIES = k_BITS_PER_INT
633 int tryPopFrontImpl(TYPE *item,
int *itemPriority,
bool blockFlag);
778: d_item(item, basicAllocator)
787: d_item(
bslmf::MovableRefUtil::move(item), basicAllocator)
801 return d_item.object();
830 enum { e_SUCCESS = 0, e_FAILURE = -1 };
840 while (0 == d_length) {
848 d_notEmptyCondition.wait(&d_mutex);
856 (bsl::uint32_t)d_notEmptyFlags);
861 Node *& head = d_heads[priority];
866 head = head->nextPtr();
871 d_notEmptyFlags &= ~(1 << priority);
878 *itemPriority = priority;
882 d_pool.deallocate(condemned);
890: d_heads((typename
NodePtrVector::size_type)k_DEFAULT_NUM_PRIORITIES, 0,
892, d_tails((typename
NodePtrVector::size_type)k_DEFAULT_NUM_PRIORITIES, 0,
895, d_pool(sizeof(
Node),
bslma::Default::allocator(basicAllocator))
898, d_allocator_p(
bslma::Default::allocator(basicAllocator))
905: d_heads((typename
NodePtrVector::size_type)numPriorities, 0, basicAllocator)
906, d_tails((typename
NodePtrVector::size_type)numPriorities, 0, basicAllocator)
908, d_pool(sizeof(
Node),
bslma::Default::allocator(basicAllocator))
911, d_allocator_p(
bslma::Default::allocator(basicAllocator))
925 for (it = d_heads.begin(), endIt = d_heads.end(); endIt != it; ++it) {
940 tryPopFrontImpl(item, itemPriority,
true);
946 enum { e_SUCCESS = 0, e_FAILURE = -1 };
948 BSLS_ASSERT((
unsigned)itemPriority < d_heads.size());
958 Node *newNode = (
Node *)d_pool.allocate();
962 ::new (newNode)
Node(item, d_allocator_p);
969 if (!d_enabledFlag) {
975 const int mask = 1 << itemPriority;
976 if (d_notEmptyFlags & mask) {
977 d_tails[itemPriority]->nextPtr() = newNode;
980 d_heads[itemPriority] = newNode;
981 d_notEmptyFlags |= mask;
983 d_tails[itemPriority] = newNode;
988 d_notEmptyCondition.signal();
997 enum { e_SUCCESS = 0, e_FAILURE = -1 };
999 BSLS_ASSERT((
unsigned)itemPriority < d_heads.size());
1009 Node *newNode =
static_cast<Node *
>(d_pool.allocate());
1019 if (!d_enabledFlag) {
1027 const int mask = 1 << itemPriority;
1028 if (d_notEmptyFlags & mask) {
1029 d_tails[itemPriority]->nextPtr() = newNode;
1032 d_heads[itemPriority] = newNode;
1033 d_notEmptyFlags |= mask;
1035 d_tails[itemPriority] = newNode;
1040 d_notEmptyCondition.signal();
1045template <
class TYPE>
1050 BSLS_ASSERT((
unsigned)itemPriority < d_heads.size());
1052 const int mask = 1 << itemPriority;
1057 for (
int ii = 0; ii < numItems; ++ii) {
1058 Node *newNode = (
Node *)d_pool.allocate();
1062 ::new (newNode)
Node(item, d_allocator_p);
1065 if (d_notEmptyFlags & mask) {
1066 d_tails[itemPriority]->nextPtr() = newNode;
1069 d_heads[itemPriority] = newNode;
1070 d_notEmptyFlags |= mask;
1072 d_tails[itemPriority] = newNode;
1078 for (
int ii = 0; ii < numItems; ++ii) {
1079 d_notEmptyCondition.signal();
1083template <
class TYPE>
1088 BSLS_ASSERT((
unsigned)itemPriority < d_heads.size());
1090 const int mask = 1 << itemPriority;
1095 for (
int ii = 0; ii < numItems; ++ii) {
1096 Node *newNode = (
Node *)d_pool.allocate();
1100 ::new (newNode)
Node(item, d_allocator_p);
1103 Node *& head = d_heads[itemPriority];
1105 d_tails[itemPriority] = newNode;
1106 d_notEmptyFlags |= mask;
1115 for (
int ii = 0; ii < numItems; ++ii) {
1116 d_notEmptyCondition.signal();
1120template <
class TYPE>
1124 return tryPopFrontImpl(item, itemPriority,
false);
1127template <
class TYPE>
1130 Node *condemnedList = 0;
1135 while (d_notEmptyFlags) {
1137 static_cast<bsl::uint32_t
>(d_notEmptyFlags));
1139 Node *& head = d_heads[priority];
1142 d_tails[priority]->nextPtr() = condemnedList;
1143 condemnedList = head;
1147 d_notEmptyFlags &= ~(1 << priority);
1155 Node *node = condemnedList;
1157 Node *condemnedNode = node;
1160 condemnedNode->~Node();
1161 d_pool.deallocate(condemnedNode);
1165template <
class TYPE>
1171 d_enabledFlag =
true;
1174template <
class TYPE>
1180 d_enabledFlag =
false;
1184template <
class TYPE>
1188 return static_cast<int>(d_heads.size());
1191template <
class TYPE>
1198template <
class TYPE>
1202 return 0 == d_length;
1205template <
class TYPE>
1209 return d_enabledFlag;
Definition bdlcc_multipriorityqueue.h:491
MultipriorityQueue_Node *& nextPtr()
Definition bdlcc_multipriorityqueue.h:806
~MultipriorityQueue_Node()
Definition bdlcc_multipriorityqueue.h:793
BSLMF_NESTED_TRAIT_DECLARATION(MultipriorityQueue_Node, bslma::UsesBslmaAllocator)
TYPE & item()
Return a reference to the non-modifiable item stored in this node.
Definition bdlcc_multipriorityqueue.h:799
Definition bdlcc_multipriorityqueue.h:566
void pushBackMultipleRaw(const TYPE &item, int itemPriority, int numItems)
Definition bdlcc_multipriorityqueue.h:1046
int pushBack(bslmf::MovableRef< TYPE > item, int itemPriority)
Definition bdlcc_multipriorityqueue.h:994
int pushBack(const TYPE &item, int itemPriority)
Definition bdlcc_multipriorityqueue.h:944
void enable()
Definition bdlcc_multipriorityqueue.h:1167
void disable()
Definition bdlcc_multipriorityqueue.h:1176
MultipriorityQueue(int numPriorities, bslma::Allocator *basicAllocator=0)
Definition bdlcc_multipriorityqueue.h:903
void popFront(TYPE *item, int *itemPriority=0)
Definition bdlcc_multipriorityqueue.h:938
void pushFrontMultipleRaw(const TYPE &item, int itemPriority, int numItems)
Definition bdlcc_multipriorityqueue.h:1084
bool isEmpty() const
Definition bdlcc_multipriorityqueue.h:1200
int length() const
Return the total number of items in this multi-priority queue.
Definition bdlcc_multipriorityqueue.h:1193
int tryPopFront(TYPE *item, int *itemPriority=0)
Definition bdlcc_multipriorityqueue.h:1122
void removeAll()
Remove and destroy all items from this multi-priority queue.
Definition bdlcc_multipriorityqueue.h:1128
int numPriorities() const
Definition bdlcc_multipriorityqueue.h:1186
bool isEnabled() const
Definition bdlcc_multipriorityqueue.h:1207
BSLMF_NESTED_TRAIT_DECLARATION(MultipriorityQueue, bslma::UsesBslmaAllocator)
MultipriorityQueue(bslma::Allocator *basicAllocator=0)
Definition bdlcc_multipriorityqueue.h:889
~MultipriorityQueue()
Definition bdlcc_multipriorityqueue.h:918
Definition bdlma_concurrentpool.h:332
Definition bslstl_vector.h:1025
Node * * iterator
Definition bslstl_vector.h:1057
Definition bslalg_constructorproxy.h:368
Definition bslma_allocator.h:457
Definition bslma_deallocatorproctor.h:312
void release()
Definition bslma_deallocatorproctor.h:384
Definition bslma_managedptr.h:1182
ManagedPtr_PairProxy< TARGET_TYPE, ManagedPtrDeleter > release()
Definition bslma_managedptr.h:2454
Definition bslmf_movableref.h:751
Definition bslmt_condition.h:220
Definition bslmt_lockguard.h:234
Definition bslmt_mutex.h:315
Definition bsls_atomic.h:743
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlcc_boundedqueue.h:270
Definition balxml_encoderoptions.h:68
Definition bdlbb_blob.h:576
static int numTrailingUnsetBits(unsigned int value)
Definition bdlb_bitutil.h:462
Definition bslma_usesbslmaallocator.h:343
static MovableRef< t_TYPE > move(t_TYPE &reference) BSLS_KEYWORD_NOEXCEPT
Definition bslmf_movableref.h:1060