8#ifndef INCLUDED_BDLCC_QUEUE
9#define INCLUDED_BDLCC_QUEUE
436#include <bdlscm_version.h>
455#include <bsl_vector.h>
489 template <
class VECTOR>
508 const int d_highWaterMark;
523 template <
class VECTOR>
524 void removeAllImp(VECTOR *buffer = 0);
533 template <
class VECTOR>
534 void tryPopFrontImp(
int maxNumItems, VECTOR *buffer);
545 template <
class VECTOR>
546 void tryPopBackImp(
int maxNumItems, VECTOR *buffer);
600 Queue(
const InitialCapacity& numItems,
612 Queue(
const InitialCapacity& numItems,
681 void removeAll(std::vector<TYPE> *buffer);
682#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
683 void removeAll(std::pmr::vector<TYPE> *buffer);
742 void tryPopFront(
int maxNumItems, std::vector<TYPE> *buffer);
743#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
744 void tryPopFront(
int maxNumItems, std::pmr::vector<TYPE> *buffer);
764 void tryPopBack(
int maxNumItems, std::vector<TYPE> *buffer);
765#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
766 void tryPopBack(
int maxNumItems, std::pmr::vector<TYPE> *buffer);
829template <
class VECTOR>
830struct Queue<TYPE>::IsVector {
832 static const bool value =
834#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
846template <
class VECTOR>
847void Queue<TYPE>::removeAllImp(VECTOR *buffer)
852 bool wasFull = d_highWaterMark > 0 && d_queue.length() >= d_highWaterMark;
855 for (
int ii = 0, len = d_queue.length(); ii < len; ++ii) {
861 lock.release()->unlock();
864 for (
int i = 0; d_highWaterMark > i; ++i) {
865 d_notFullCondition.signal();
871template <
class VECTOR>
872void Queue<TYPE>::tryPopFrontImp(
int maxNumItems, VECTOR *buffer)
880 int length = d_queue.length();
881 const bool wasFull = d_highWaterMark > 0 && length >= d_highWaterMark;
883 for (; d_queue.length() > 0 && maxNumItems > 0; --maxNumItems) {
892 if (wasFull && length < d_highWaterMark) {
893 numSignal = d_highWaterMark - length;
897 for (; 0 < numSignal; --numSignal) {
898 d_notFullCondition.signal();
903template <
class VECTOR>
904void Queue<TYPE>::tryPopBackImp(
int maxNumItems, VECTOR *buffer)
912 int length = d_queue.length();
913 const bool wasFull = d_highWaterMark > 0 && length >= d_highWaterMark;
915 for (; d_queue.length() > 0 && maxNumItems > 0; --maxNumItems) {
923 if (wasFull && length < d_highWaterMark) {
924 numSignal = d_highWaterMark - length;
928 for (; 0 < numSignal; --numSignal) {
929 d_notFullCondition.signal();
937: d_queue(basicAllocator)
954: d_queue(basicAllocator)
955, d_highWaterMark(highWaterMark < 0 ? -1 : highWaterMark)
965, d_highWaterMark(highWaterMark < 0 ? -1 : highWaterMark)
973: d_queue(srcQueue, basicAllocator)
983: d_queue(srcQueue, basicAllocator)
984, d_highWaterMark(highWaterMark < 0 ? -1 : highWaterMark)
1002 while (0 == (length = d_queue.length())) {
1003 d_notEmptyCondition.wait(&d_mutex);
1005 *buffer = d_queue.back();
1010 if (length < (
unsigned) d_highWaterMark) {
1011 d_notFullCondition.signal();
1015template <
class TYPE>
1021 unsigned int length;
1025 while (0 == (length = d_queue.length())) {
1026 d_notEmptyCondition.wait(&d_mutex);
1028 TYPE back = d_queue.back();
1034 if (length < (
unsigned) d_highWaterMark) {
1035 d_notFullCondition.signal();
1040template <
class TYPE>
1043 unsigned int length;
1047 while (0 == (length = d_queue.length())) {
1048 if (d_notEmptyCondition.timedWait(&d_mutex, timeout)) {
1052 *buffer = d_queue.back();
1057 if (length < (
unsigned) d_highWaterMark) {
1058 d_notFullCondition.signal();
1063template <
class TYPE>
1066 unsigned int length;
1070 while (0 == (length = d_queue.length())) {
1071 d_notEmptyCondition.wait(&d_mutex);
1073 *buffer = d_queue.front();
1078 if (length < (
unsigned) d_highWaterMark) {
1079 d_notFullCondition.signal();
1083template <
class TYPE>
1089 unsigned int length;
1093 while (0 == (length = d_queue.length())) {
1094 d_notEmptyCondition.wait(&d_mutex);
1096 TYPE front = d_queue.front();
1102 if (length < (
unsigned) d_highWaterMark) {
1103 d_notFullCondition.signal();
1108template <
class TYPE>
1111 unsigned int length;
1115 while (0 == (length = d_queue.length())) {
1116 if (d_notEmptyCondition.timedWait(&d_mutex, timeout)) {
1120 *buffer = d_queue.front();
1125 if (length < (
unsigned) d_highWaterMark) {
1126 d_notFullCondition.signal();
1131template <
class TYPE>
1134 unsigned int length;
1138 if (0 == (length = d_queue.length())) {
1141 *buffer = d_queue.front();
1146 if (length < (
unsigned) d_highWaterMark) {
1147 d_notFullCondition.signal();
1152template <
class TYPE>
1159template <
class TYPE>
1163 tryPopFrontImp(maxNumItems, buffer);
1166template <
class TYPE>
1170 tryPopFrontImp(maxNumItems, buffer);
1173#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
1174template <
class TYPE>
1178 tryPopFrontImp(maxNumItems, buffer);
1182template <
class TYPE>
1185 unsigned int length;
1189 if (0 == (length = d_queue.length())) {
1192 *buffer = d_queue.back();
1197 if (length < (
unsigned) d_highWaterMark) {
1198 d_notFullCondition.signal();
1203template <
class TYPE>
1210template <
class TYPE>
1214 tryPopBackImp(maxNumItems, buffer);
1217template <
class TYPE>
1221 tryPopBackImp(maxNumItems, buffer);
1224#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
1225template <
class TYPE>
1229 tryPopBackImp(maxNumItems, buffer);
1233template <
class TYPE>
1239template <
class TYPE>
1242 removeAllImp(buffer);
1245template <
class TYPE>
1248 removeAllImp(buffer);
1251#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
1252template <
class TYPE>
1255 removeAllImp(buffer);
1259template <
class TYPE>
1264 if (d_highWaterMark >= 0) {
1265 while (d_queue.length() >= d_highWaterMark) {
1266 d_notFullCondition.wait(&d_mutex);
1269 d_queue.pushBack(item);
1272 d_notEmptyCondition.signal();
1275template <
class TYPE>
1280 if (d_highWaterMark >= 0) {
1281 while (d_queue.length() >= d_highWaterMark) {
1282 d_notFullCondition.wait(&d_mutex);
1285 d_queue.pushFront(item);
1288 d_notEmptyCondition.signal();
1291template <
class TYPE>
1297 if (d_highWaterMark >= 0) {
1298 while (d_queue.length() >= d_highWaterMark) {
1299 if (d_notFullCondition.timedWait(&d_mutex, timeout)) {
1304 d_queue.pushBack(item);
1307 d_notEmptyCondition.signal();
1311template <
class TYPE>
1317 if (d_highWaterMark >= 0) {
1318 while (d_queue.length() >= d_highWaterMark) {
1319 if (d_notFullCondition.timedWait(&d_mutex, timeout)) {
1324 d_queue.pushFront(item);
1327 d_notEmptyCondition.signal();
1331template <
class TYPE>
1337 d_queue.pushFront(item);
1339 d_notEmptyCondition.signal();
1344template <
class TYPE>
1348 return d_notEmptyCondition;
1351template <
class TYPE>
1355 return d_notFullCondition;
1358template <
class TYPE>
1365template <
class TYPE>
1369 return d_notEmptyCondition;
1372template <
class TYPE>
1376 return d_notFullCondition;
1379template <
class TYPE>
1387template <
class TYPE>
1391 return d_highWaterMark;
1394template <
class TYPE>
1400 return d_queue.length();
Definition bdlc_queue.h:273
Definition bdlcc_queue.h:476
int tryPopBack(TYPE *buffer)
Definition bdlcc_queue.h:1183
bslmt::Condition & insertCondition()
Definition bdlcc_queue.h:1353
bdlc::Queue< TYPE > & queue()
Definition bdlcc_queue.h:1381
int length() const
Definition bdlcc_queue.h:1396
~Queue()
Definition bdlcc_queue.h:990
void removeAll()
Definition bdlcc_queue.h:1234
int tryPopFront(TYPE *buffer)
Definition bdlcc_queue.h:1132
bslmt::Condition & notFullCondition()
Definition bdlcc_queue.h:1374
TYPE popFront()
Definition bdlcc_queue.h:1084
bslmt::Condition & notEmptyCondition()
Definition bdlcc_queue.h:1367
int timedPushFront(const TYPE &item, const bsls::TimeInterval &timeout)
Definition bdlcc_queue.h:1312
void pushBack(const TYPE &item)
Definition bdlcc_queue.h:1260
bslmt::Mutex & mutex()
Definition bdlcc_queue.h:1360
BSLMF_NESTED_TRAIT_DECLARATION(Queue, bslma::UsesBslmaAllocator)
void pushFront(const TYPE &item)
Definition bdlcc_queue.h:1276
int timedPopFront(TYPE *buffer, const bsls::TimeInterval &timeout)
Definition bdlcc_queue.h:1109
int highWaterMark() const
Definition bdlcc_queue.h:1389
int timedPopBack(TYPE *buffer, const bsls::TimeInterval &timeout)
Definition bdlcc_queue.h:1041
bslmt::Condition & condition()
Definition bdlcc_queue.h:1346
void forcePushFront(const TYPE &item)
Definition bdlcc_queue.h:1333
int timedPushBack(const TYPE &item, const bsls::TimeInterval &timeout)
Definition bdlcc_queue.h:1292
TYPE popBack()
Definition bdlcc_queue.h:1016
Definition bslstl_vector.h:1025
Definition bslma_allocator.h:457
Definition bslmt_condition.h:220
Definition bslmt_lockguard.h:234
T * release()
Definition bslmt_lockguard.h:493
Definition bslmt_mutex.h:315
Definition bsls_timeinterval.h:301
#define BSLMF_ASSERT(expr)
Definition bslmf_assert.h:229
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlcc_boundedqueue.h:270
Definition bdlc_queue.h:295
Definition bdlcc_queue.h:562
InitialCapacity(int i)
Create an object with the specified value i.
Definition bdlcc_queue.h:570
unsigned int d_i
Definition bdlcc_queue.h:565
Definition bslmf_issame.h:146
Definition bslma_usesbslmaallocator.h:343
static MovableRef< t_TYPE > move(t_TYPE &reference) BSLS_KEYWORD_NOEXCEPT
Definition bslmf_movableref.h:1060