8#ifndef INCLUDED_BDLCC_FIXEDQUEUE
9#define INCLUDED_BDLCC_FIXEDQUEUE
238#include <bdlscm_version.h>
260#include <bsl_algorithm.h>
261#include <bsl_vector.h>
292 const char d_elementsPad[k_TYPE_PADDING];
305 const char d_popControlSemaPad[k_SEMA_PADDING];
315 const char d_pushControlSemaPad[k_SEMA_PADDING];
441template <
class VALUE>
449 unsigned int d_generation;
452 unsigned int d_index;
471 unsigned int generation,
492template <
class VALUE>
499 unsigned int d_generation;
503 unsigned int d_index;
522 unsigned int generation,
553, d_impl(capacity, basicAllocator)
554, d_numWaitingPoppers(0)
556, d_popControlSemaPad()
557, d_numWaitingPushers(0)
558, d_pushControlSema(0)
559, d_pushControlSemaPad()
560, d_allocator_p(
bslma::Default::allocator(basicAllocator))
562 d_elements =
static_cast<TYPE *
>(
570 d_allocator_p->deallocate(d_elements);
576 unsigned int generation;
587 int retval = d_impl.reservePushIndex(&generation, &index);
604 d_impl.commitPushIndex(generation, index);
607 d_popControlSema.post();
616 unsigned int generation;
627 int retval = d_impl.reservePushIndex(&generation, &index);
645 d_impl.commitPushIndex(generation, index);
648 d_popControlSema.post();
657 unsigned int generation;
668 int retval = d_impl.reservePopIndex(&generation, &index);
683#if defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
686 *value = d_elements[index];
696 while (0 != (retval = tryPushBack(value))) {
703 d_numWaitingPushers.addRelaxed(1);
713 if (isFull() && isEnabled()) {
714 d_pushControlSema.wait();
717 d_numWaitingPushers.addRelaxed(-1);
734 d_numWaitingPushers.addRelaxed(1);
744 if (isFull() && isEnabled()) {
745 d_pushControlSema.wait();
748 d_numWaitingPushers.addRelaxed(-1);
757 while (0 != tryPopFront(value)) {
758 d_numWaitingPoppers.addRelaxed(1);
769 d_popControlSema.wait();
772 d_numWaitingPoppers.addRelaxed(-1);
779 unsigned int generation;
782 while (0 != d_impl.reservePopIndex(&generation, &index)) {
783 d_numWaitingPoppers.addRelaxed(1);
786 d_popControlSema.wait();
789 d_numWaitingPoppers.addRelaxed(-1);
801#if defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
804 return TYPE(d_elements[index]);
811 const int numItems = numElements();
813 while (poppedItems++ < numItems) {
815 unsigned int generation;
817 if (0 != d_impl.reservePopIndex(&generation, &index)) {
821 bslma::DestructionUtil::destroy(d_elements + index);
822 d_impl.commitPopIndex(generation, index);
825 int numWakeUps = bsl::min(poppedItems,
826 static_cast<int>(d_numWaitingPushers));
827 while (numWakeUps--) {
830 d_pushControlSema.post();
839 const int numWaitingPushers = d_numWaitingPushers;
841 for (
int i = 0; i < numWaitingPushers; ++i) {
842 d_pushControlSema.post();
858 return static_cast<int>(d_impl.capacity());
865 return (0 >= numElements());
872 return d_impl.isEnabled();
879 return (capacity() <= numElements());
886 return numElements();
893 return static_cast<int>(d_impl.length());
900 return static_cast<int>(capacity());
908template <
class VALUE>
911 unsigned int generation,
914, d_generation(generation)
919template <
class VALUE>
927 bslma::DestructionUtil::destroy(d_parent_p->d_elements + d_index);
929 d_parent_p->d_impl.commitPopIndex(d_generation, d_index);
934 d_parent_p->d_numWaitingPushers)) {
935 d_parent_p->d_pushControlSema.post();
944template <
class VALUE>
948 unsigned int generation,
951, d_generation(generation)
956template <
class VALUE>
963 unsigned int generation, index;
969 while (0 == d_parent_p->d_impl.reservePopIndexForClear(&generation,
973 bslma::DestructionUtil::destroy(d_parent_p->d_elements + index);
976 d_parent_p->d_impl.commitPopIndex(generation, index);
981 d_parent_p->d_impl.abortPushIndexReservation(d_generation, d_index);
983 while (poppedItems--) {
986 d_parent_p->d_pushControlSema.post();
992template <
class VALUE>
Definition bdlcc_fixedqueueindexmanager.h:257
Definition bdlcc_fixedqueue.h:442
~FixedQueue_PopGuard()
Definition bdlcc_fixedqueue.h:920
Definition bdlcc_fixedqueue.h:493
~FixedQueue_PushProctor()
Definition bdlcc_fixedqueue.h:957
void release()
Definition bdlcc_fixedqueue.h:994
Definition bdlcc_fixedqueue.h:274
~FixedQueue()
Destroy this object.
Definition bdlcc_fixedqueue.h:567
bool isFull() const
Definition bdlcc_fixedqueue.h:877
void removeAll()
Definition bdlcc_fixedqueue.h:809
bool isEnabled() const
Definition bdlcc_fixedqueue.h:870
int size() const
[DEPRECATED] Invoke capacity.
Definition bdlcc_fixedqueue.h:898
int capacity() const
Definition bdlcc_fixedqueue.h:856
int length() const
[DEPRECATED] Invoke numElements.
Definition bdlcc_fixedqueue.h:884
int pushBack(const TYPE &value)
Definition bdlcc_fixedqueue.h:693
void enable()
Definition bdlcc_fixedqueue.h:848
int numElements() const
Returns the number of elements currently in this queue.
Definition bdlcc_fixedqueue.h:891
int tryPushBack(bslmf::MovableRef< TYPE > value)
Definition bdlcc_fixedqueue.h:614
TYPE popFront()
Definition bdlcc_fixedqueue.h:777
void disable()
Definition bdlcc_fixedqueue.h:835
bool isEmpty() const
Definition bdlcc_fixedqueue.h:863
BSLMF_NESTED_TRAIT_DECLARATION(FixedQueue, bslma::UsesBslmaAllocator)
int pushBack(bslmf::MovableRef< TYPE > value)
Definition bdlcc_fixedqueue.h:724
FixedQueue(bsl::size_t capacity, bslma::Allocator *basicAllocator=0)
Definition bdlcc_fixedqueue.h:549
int tryPushBack(const TYPE &value)
Definition bdlcc_fixedqueue.h:574
int tryPopFront(TYPE *value)
Definition bdlcc_fixedqueue.h:655
void popFront(TYPE *value)
Definition bdlcc_fixedqueue.h:755
Definition bslma_allocator.h:457
virtual void * allocate(size_type size)=0
Definition bslmf_movableref.h:751
Definition bslmt_semaphore.h:168
Definition bsls_atomic.h:743
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlcc_boundedqueue.h:270
Definition balxml_encoderoptions.h:68
static void moveConstruct(TARGET_TYPE *address, TARGET_TYPE &original, bslma::Allocator *allocator)
Definition bslalg_scalarprimitives.h:1642
static void copyConstruct(TARGET_TYPE *address, const TARGET_TYPE &original, bslma::Allocator *allocator)
Definition bslalg_scalarprimitives.h:1599
Definition bslma_usesbslmaallocator.h:343
static MovableRef< t_TYPE > move(t_TYPE &reference) BSLS_KEYWORD_NOEXCEPT
Definition bslmf_movableref.h:1060