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];
445template <
class VALUE>
453 unsigned int d_generation;
456 unsigned int d_index;
476 unsigned int generation,
498template <
class VALUE>
505 unsigned int d_generation;
509 unsigned int d_index;
529 unsigned int generation,
560, d_impl(capacity, basicAllocator)
561, d_numWaitingPoppers(0)
563, d_popControlSemaPad()
564, d_numWaitingPushers(0)
565, d_pushControlSema(0)
566, d_pushControlSemaPad()
567, d_allocator_p(
bslma::Default::allocator(basicAllocator))
569 d_elements =
static_cast<TYPE *
>(
577 d_allocator_p->deallocate(d_elements);
583 unsigned int generation;
594 int retval = d_impl.reservePushIndex(&generation, &index);
611 d_impl.commitPushIndex(generation, index);
614 d_popControlSema.post();
623 unsigned int generation;
634 int retval = d_impl.reservePushIndex(&generation, &index);
652 d_impl.commitPushIndex(generation, index);
655 d_popControlSema.post();
664 unsigned int generation;
675 int retval = d_impl.reservePopIndex(&generation, &index);
690#if defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
693 *value = d_elements[index];
703 while (0 != (retval = tryPushBack(value))) {
710 d_numWaitingPushers.addRelaxed(1);
720 if (isFull() && isEnabled()) {
721 d_pushControlSema.wait();
724 d_numWaitingPushers.addRelaxed(-1);
741 d_numWaitingPushers.addRelaxed(1);
751 if (isFull() && isEnabled()) {
752 d_pushControlSema.wait();
755 d_numWaitingPushers.addRelaxed(-1);
764 while (0 != tryPopFront(value)) {
765 d_numWaitingPoppers.addRelaxed(1);
776 d_popControlSema.wait();
779 d_numWaitingPoppers.addRelaxed(-1);
786 unsigned int generation;
789 while (0 != d_impl.reservePopIndex(&generation, &index)) {
790 d_numWaitingPoppers.addRelaxed(1);
793 d_popControlSema.wait();
796 d_numWaitingPoppers.addRelaxed(-1);
808#if defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
811 return TYPE(d_elements[index]);
818 const int numItems = numElements();
820 while (poppedItems++ < numItems) {
822 unsigned int generation;
824 if (0 != d_impl.reservePopIndex(&generation, &index)) {
828 bslma::DestructionUtil::destroy(d_elements + index);
829 d_impl.commitPopIndex(generation, index);
832 int numWakeUps = bsl::min(poppedItems,
833 static_cast<int>(d_numWaitingPushers));
834 while (numWakeUps--) {
837 d_pushControlSema.post();
846 const int numWaitingPushers = d_numWaitingPushers;
848 for (
int i = 0; i < numWaitingPushers; ++i) {
849 d_pushControlSema.post();
865 return static_cast<int>(d_impl.capacity());
872 return (0 >= numElements());
879 return d_impl.isEnabled();
886 return (capacity() <= numElements());
893 return numElements();
900 return static_cast<int>(d_impl.length());
907 return static_cast<int>(capacity());
915template <
class VALUE>
918 unsigned int generation,
921, d_generation(generation)
926template <
class VALUE>
934 bslma::DestructionUtil::destroy(d_parent_p->d_elements + d_index);
936 d_parent_p->d_impl.commitPopIndex(d_generation, d_index);
941 d_parent_p->d_numWaitingPushers)) {
942 d_parent_p->d_pushControlSema.post();
951template <
class VALUE>
955 unsigned int generation,
958, d_generation(generation)
963template <
class VALUE>
970 unsigned int generation, index;
976 while (0 == d_parent_p->d_impl.reservePopIndexForClear(&generation,
980 bslma::DestructionUtil::destroy(d_parent_p->d_elements + index);
983 d_parent_p->d_impl.commitPopIndex(generation, index);
988 d_parent_p->d_impl.abortPushIndexReservation(d_generation, d_index);
990 while (poppedItems--) {
993 d_parent_p->d_pushControlSema.post();
999template <
class VALUE>
Definition bdlcc_fixedqueueindexmanager.h:257
Definition bdlcc_fixedqueue.h:446
~FixedQueue_PopGuard()
Definition bdlcc_fixedqueue.h:927
Definition bdlcc_fixedqueue.h:499
~FixedQueue_PushProctor()
Definition bdlcc_fixedqueue.h:964
void release()
Definition bdlcc_fixedqueue.h:1001
Definition bdlcc_fixedqueue.h:274
~FixedQueue()
Destroy this object.
Definition bdlcc_fixedqueue.h:574
bool isFull() const
Definition bdlcc_fixedqueue.h:884
void removeAll()
Definition bdlcc_fixedqueue.h:816
bool isEnabled() const
Definition bdlcc_fixedqueue.h:877
int size() const
Definition bdlcc_fixedqueue.h:905
int capacity() const
Definition bdlcc_fixedqueue.h:863
int length() const
Definition bdlcc_fixedqueue.h:891
int pushBack(const TYPE &value)
Definition bdlcc_fixedqueue.h:700
void enable()
Definition bdlcc_fixedqueue.h:855
int numElements() const
Returns the number of elements currently in this queue.
Definition bdlcc_fixedqueue.h:898
int tryPushBack(bslmf::MovableRef< TYPE > value)
Definition bdlcc_fixedqueue.h:621
TYPE popFront()
Definition bdlcc_fixedqueue.h:784
void disable()
Definition bdlcc_fixedqueue.h:842
bool isEmpty() const
Definition bdlcc_fixedqueue.h:870
BSLMF_NESTED_TRAIT_DECLARATION(FixedQueue, bslma::UsesBslmaAllocator)
int pushBack(bslmf::MovableRef< TYPE > value)
Definition bdlcc_fixedqueue.h:731
FixedQueue(bsl::size_t capacity, bslma::Allocator *basicAllocator=0)
Definition bdlcc_fixedqueue.h:556
int tryPushBack(const TYPE &value)
Definition bdlcc_fixedqueue.h:581
int tryPopFront(TYPE *value)
Definition bdlcc_fixedqueue.h:662
void popFront(TYPE *value)
Definition bdlcc_fixedqueue.h:762
Definition bslma_allocator.h:545
virtual void * allocate(size_type size)=0
Definition bslmf_movableref.h:752
Definition bslmt_semaphore.h:169
Definition bsls_atomic.h:744
#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 baljsn_encoder_testtypes.h:76
static void moveConstruct(TARGET_TYPE *address, TARGET_TYPE &original, bslma::Allocator *allocator)
Definition bslalg_scalarprimitives.h:1660
static void copyConstruct(TARGET_TYPE *address, const TARGET_TYPE &original, bslma::Allocator *allocator)
Definition bslalg_scalarprimitives.h:1617
Definition bslma_usesbslmaallocator.h:344
static MovableRef< t_TYPE > move(t_TYPE &reference) BSLS_KEYWORD_NOEXCEPT
Definition bslmf_movableref.h:1067