8#ifndef INCLUDED_BDLCC_QUEUE
9#define INCLUDED_BDLCC_QUEUE
436#include <bdlscm_version.h>
455#include <bsl_vector.h>
490 template <
class VECTOR>
509 const int d_highWaterMark;
524 template <
class VECTOR>
525 void removeAllImp(VECTOR *buffer = 0);
535 template <
class VECTOR>
536 void tryPopFrontImp(
int maxNumItems, VECTOR *buffer);
549 template <
class VECTOR>
550 void tryPopBackImp(
int maxNumItems, VECTOR *buffer);
607 Queue(
const InitialCapacity& numItems,
620 Queue(
const InitialCapacity& numItems,
691 void removeAll(std::vector<TYPE> *buffer);
692#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
693 void removeAll(std::pmr::vector<TYPE> *buffer);
753 void tryPopFront(
int maxNumItems, std::vector<TYPE> *buffer);
754#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
755 void tryPopFront(
int maxNumItems, std::pmr::vector<TYPE> *buffer);
775 void tryPopBack(
int maxNumItems, std::vector<TYPE> *buffer);
776#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
777 void tryPopBack(
int maxNumItems, std::pmr::vector<TYPE> *buffer);
842template <
class VECTOR>
843struct Queue<TYPE>::IsVector {
845 static const bool value =
847#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
859template <
class VECTOR>
860void Queue<TYPE>::removeAllImp(VECTOR *buffer)
865 bool wasFull = d_highWaterMark > 0 && d_queue.length() >= d_highWaterMark;
868 for (
int ii = 0, len = d_queue.length(); ii < len; ++ii) {
874 lock.release()->unlock();
877 for (
int i = 0; d_highWaterMark > i; ++i) {
878 d_notFullCondition.signal();
884template <
class VECTOR>
885void Queue<TYPE>::tryPopFrontImp(
int maxNumItems, VECTOR *buffer)
893 int length = d_queue.length();
894 const bool wasFull = d_highWaterMark > 0 && length >= d_highWaterMark;
896 for (; d_queue.length() > 0 && maxNumItems > 0; --maxNumItems) {
905 if (wasFull && length < d_highWaterMark) {
906 numSignal = d_highWaterMark - length;
910 for (; 0 < numSignal; --numSignal) {
911 d_notFullCondition.signal();
916template <
class VECTOR>
917void Queue<TYPE>::tryPopBackImp(
int maxNumItems, VECTOR *buffer)
925 int length = d_queue.length();
926 const bool wasFull = d_highWaterMark > 0 && length >= d_highWaterMark;
928 for (; d_queue.length() > 0 && maxNumItems > 0; --maxNumItems) {
936 if (wasFull && length < d_highWaterMark) {
937 numSignal = d_highWaterMark - length;
941 for (; 0 < numSignal; --numSignal) {
942 d_notFullCondition.signal();
950: d_queue(basicAllocator)
967: d_queue(basicAllocator)
968, d_highWaterMark(highWaterMark < 0 ? -1 : highWaterMark)
978, d_highWaterMark(highWaterMark < 0 ? -1 : highWaterMark)
986: d_queue(srcQueue, basicAllocator)
996: d_queue(srcQueue, basicAllocator)
997, d_highWaterMark(highWaterMark < 0 ? -1 : highWaterMark)
1001template <
class TYPE>
1008template <
class TYPE>
1011 unsigned int length;
1015 while (0 == (length = d_queue.length())) {
1016 d_notEmptyCondition.wait(&d_mutex);
1018 *buffer = d_queue.back();
1023 if (length < (
unsigned) d_highWaterMark) {
1024 d_notFullCondition.signal();
1028template <
class TYPE>
1034 unsigned int length;
1038 while (0 == (length = d_queue.length())) {
1039 d_notEmptyCondition.wait(&d_mutex);
1041 TYPE back = d_queue.back();
1047 if (length < (
unsigned) d_highWaterMark) {
1048 d_notFullCondition.signal();
1053template <
class TYPE>
1056 unsigned int length;
1060 while (0 == (length = d_queue.length())) {
1061 if (d_notEmptyCondition.timedWait(&d_mutex, timeout)) {
1065 *buffer = d_queue.back();
1070 if (length < (
unsigned) d_highWaterMark) {
1071 d_notFullCondition.signal();
1076template <
class TYPE>
1079 unsigned int length;
1083 while (0 == (length = d_queue.length())) {
1084 d_notEmptyCondition.wait(&d_mutex);
1086 *buffer = d_queue.front();
1091 if (length < (
unsigned) d_highWaterMark) {
1092 d_notFullCondition.signal();
1096template <
class TYPE>
1102 unsigned int length;
1106 while (0 == (length = d_queue.length())) {
1107 d_notEmptyCondition.wait(&d_mutex);
1109 TYPE front = d_queue.front();
1115 if (length < (
unsigned) d_highWaterMark) {
1116 d_notFullCondition.signal();
1121template <
class TYPE>
1124 unsigned int length;
1128 while (0 == (length = d_queue.length())) {
1129 if (d_notEmptyCondition.timedWait(&d_mutex, timeout)) {
1133 *buffer = d_queue.front();
1138 if (length < (
unsigned) d_highWaterMark) {
1139 d_notFullCondition.signal();
1144template <
class TYPE>
1147 unsigned int length;
1151 if (0 == (length = d_queue.length())) {
1154 *buffer = d_queue.front();
1159 if (length < (
unsigned) d_highWaterMark) {
1160 d_notFullCondition.signal();
1165template <
class TYPE>
1172template <
class TYPE>
1176 tryPopFrontImp(maxNumItems, buffer);
1179template <
class TYPE>
1183 tryPopFrontImp(maxNumItems, buffer);
1186#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
1187template <
class TYPE>
1191 tryPopFrontImp(maxNumItems, buffer);
1195template <
class TYPE>
1198 unsigned int length;
1202 if (0 == (length = d_queue.length())) {
1205 *buffer = d_queue.back();
1210 if (length < (
unsigned) d_highWaterMark) {
1211 d_notFullCondition.signal();
1216template <
class TYPE>
1223template <
class TYPE>
1227 tryPopBackImp(maxNumItems, buffer);
1230template <
class TYPE>
1234 tryPopBackImp(maxNumItems, buffer);
1237#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
1238template <
class TYPE>
1242 tryPopBackImp(maxNumItems, buffer);
1246template <
class TYPE>
1252template <
class TYPE>
1255 removeAllImp(buffer);
1258template <
class TYPE>
1261 removeAllImp(buffer);
1264#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
1265template <
class TYPE>
1268 removeAllImp(buffer);
1272template <
class TYPE>
1277 if (d_highWaterMark >= 0) {
1278 while (d_queue.length() >= d_highWaterMark) {
1279 d_notFullCondition.wait(&d_mutex);
1282 d_queue.pushBack(item);
1285 d_notEmptyCondition.signal();
1288template <
class TYPE>
1293 if (d_highWaterMark >= 0) {
1294 while (d_queue.length() >= d_highWaterMark) {
1295 d_notFullCondition.wait(&d_mutex);
1298 d_queue.pushFront(item);
1301 d_notEmptyCondition.signal();
1304template <
class TYPE>
1310 if (d_highWaterMark >= 0) {
1311 while (d_queue.length() >= d_highWaterMark) {
1312 if (d_notFullCondition.timedWait(&d_mutex, timeout)) {
1317 d_queue.pushBack(item);
1320 d_notEmptyCondition.signal();
1324template <
class TYPE>
1330 if (d_highWaterMark >= 0) {
1331 while (d_queue.length() >= d_highWaterMark) {
1332 if (d_notFullCondition.timedWait(&d_mutex, timeout)) {
1337 d_queue.pushFront(item);
1340 d_notEmptyCondition.signal();
1344template <
class TYPE>
1350 d_queue.pushFront(item);
1352 d_notEmptyCondition.signal();
1357template <
class TYPE>
1361 return d_notEmptyCondition;
1364template <
class TYPE>
1368 return d_notFullCondition;
1371template <
class TYPE>
1378template <
class TYPE>
1382 return d_notEmptyCondition;
1385template <
class TYPE>
1389 return d_notFullCondition;
1392template <
class TYPE>
1400template <
class TYPE>
1404 return d_highWaterMark;
1407template <
class TYPE>
1413 return d_queue.length();
Definition bdlc_queue.h:274
Definition bdlcc_queue.h:477
int tryPopBack(TYPE *buffer)
Definition bdlcc_queue.h:1196
bslmt::Condition & insertCondition()
Definition bdlcc_queue.h:1366
bdlc::Queue< TYPE > & queue()
Definition bdlcc_queue.h:1394
int length() const
Definition bdlcc_queue.h:1409
~Queue()
Definition bdlcc_queue.h:1003
void removeAll()
Definition bdlcc_queue.h:1247
int tryPopFront(TYPE *buffer)
Definition bdlcc_queue.h:1145
bslmt::Condition & notFullCondition()
Definition bdlcc_queue.h:1387
TYPE popFront()
Definition bdlcc_queue.h:1097
bslmt::Condition & notEmptyCondition()
Definition bdlcc_queue.h:1380
int timedPushFront(const TYPE &item, const bsls::TimeInterval &timeout)
Definition bdlcc_queue.h:1325
void pushBack(const TYPE &item)
Definition bdlcc_queue.h:1273
bslmt::Mutex & mutex()
Definition bdlcc_queue.h:1373
BSLMF_NESTED_TRAIT_DECLARATION(Queue, bslma::UsesBslmaAllocator)
void pushFront(const TYPE &item)
Definition bdlcc_queue.h:1289
int timedPopFront(TYPE *buffer, const bsls::TimeInterval &timeout)
Definition bdlcc_queue.h:1122
int highWaterMark() const
Definition bdlcc_queue.h:1402
int timedPopBack(TYPE *buffer, const bsls::TimeInterval &timeout)
Definition bdlcc_queue.h:1054
bslmt::Condition & condition()
Definition bdlcc_queue.h:1359
void forcePushFront(const TYPE &item)
Definition bdlcc_queue.h:1346
int timedPushBack(const TYPE &item, const bsls::TimeInterval &timeout)
Definition bdlcc_queue.h:1305
TYPE popBack()
Definition bdlcc_queue.h:1029
Definition bslstl_vector.h:1120
Definition bslma_allocator.h:545
Definition bslmt_condition.h:220
Definition bslmt_lockguard.h:234
T * release()
Definition bslmt_lockguard.h:506
Definition bslmt_mutex.h:317
Definition bsls_timeinterval.h:307
#define BSLMF_ASSERT(expr)
Definition bslmf_assert.h:231
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bdlcc_boundedqueue.h:270
Definition bdlc_queue.h:298
Definition bdlcc_queue.h:568
InitialCapacity(int i)
Create an object with the specified value i.
Definition bdlcc_queue.h:576
unsigned int d_i
Definition bdlcc_queue.h:571
Definition bslmf_issame.h:146
Definition bslma_usesbslmaallocator.h:344
static MovableRef< t_TYPE > move(t_TYPE &reference) BSLS_KEYWORD_NOEXCEPT
Definition bslmf_movableref.h:1067