Quick Links:

bal | bbl | bdl | bsl

Public Types | Public Member Functions | Friends

bdlcc::BoundedQueue< TYPE > Class Template Reference

#include <bdlcc_boundedqueue.h>

List of all members.

Public Types

enum  {
  e_SUCCESS = 0, e_EMPTY = -1, e_FULL = -2, e_DISABLED = -3,
  e_FAILED = -4
}
typedef TYPE value_type

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (BoundedQueue, bslma::UsesBslmaAllocator)
 BoundedQueue (bsl::size_t capacity, bslma::Allocator *basicAllocator=0)
 ~BoundedQueue ()
int popFront (TYPE *value)
int pushBack (const TYPE &value)
int pushBack (bslmf::MovableRef< TYPE > value)
void removeAll ()
int tryPopFront (TYPE *value)
int tryPushBack (const TYPE &value)
int tryPushBack (bslmf::MovableRef< TYPE > value)
void disablePopFront ()
void disablePushBack ()
void enablePopFront ()
void enablePushBack ()
bsl::size_t capacity () const
bool isEmpty () const
bool isFull () const
bool isPopFrontDisabled () const
bool isPushBackDisabled () const
bsl::size_t numElements () const
int waitUntilEmpty () const
bslma::Allocatorallocator () const

Friends

class BoundedQueue_PopCompleteGuard< BoundedQueue< TYPE >, typename BoundedQueue< TYPE >::Node >
class BoundedQueue_PushExceptionCompleteProctor< BoundedQueue< TYPE > >

Detailed Description

template<class TYPE>
class bdlcc::BoundedQueue< TYPE >

This class provides a thread-safe bounded queue of values.

See Component bdlcc_boundedqueue


Member Typedef Documentation

template<class TYPE>
typedef TYPE bdlcc::BoundedQueue< TYPE >::value_type

The type for elements.


Member Enumeration Documentation

template<class TYPE>
anonymous enum
Enumerator:
e_SUCCESS 

must be 0

e_EMPTY 
e_FULL 
e_DISABLED 
e_FAILED 

Constructor & Destructor Documentation

template<class TYPE>
bdlcc::BoundedQueue< TYPE >::BoundedQueue ( bsl::size_t  capacity,
bslma::Allocator basicAllocator = 0 
) [explicit]

Create a thread-aware queue with at least the specified capacity. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

template<class TYPE>
bdlcc::BoundedQueue< TYPE >::~BoundedQueue (  ) 

Destroy this object.


Member Function Documentation

template<class TYPE>
bdlcc::BoundedQueue< TYPE >::BSLMF_NESTED_TRAIT_DECLARATION ( BoundedQueue< TYPE >  ,
bslma::UsesBslmaAllocator   
)
template<class TYPE>
int bdlcc::BoundedQueue< TYPE >::popFront ( TYPE *  value  ) 

Remove the element from the front of this queue and load that element into the specified value. If the queue is empty, block until it is not empty. Return 0 on success, and a non-zero value otherwise. Specifically, return e_SUCCESS on success, e_DISABLED if isPopFrontDisabled() and e_FAILED if an error occurs. On failure, value is not changed. Threads blocked due to the queue being empty will return e_DISABLED if disablePopFront is invoked.

template<class TYPE>
int bdlcc::BoundedQueue< TYPE >::pushBack ( const TYPE &  value  ) 

Append the specified value to the back of this queue. If the queue is full, block until it is not full. Return 0 on success, and a non-zero value otherwise. Specifically, return e_SUCCESS on success, e_DISABLED if isPushBackDisabled() and e_FAILED if an error occurs. Threads blocked due to the queue being full will return e_DISABLED if disablePushBack is invoked.

template<class TYPE>
int bdlcc::BoundedQueue< TYPE >::pushBack ( bslmf::MovableRef< TYPE >  value  ) 

Append the specified move-insertable value to the back of this queue. If the queue is full, block until it is not full. value is left in a valid but unspecified state. Return 0 on success, and a non-zero value otherwise. Specifically, return e_SUCCESS on success, e_DISABLED if isPushBackDisabled() and e_FAILED if an error occurs. On failure, value is not changed. Threads blocked due to the queue being full will return e_DISABLED if disablePushBack is invoked.

template<class TYPE>
void bdlcc::BoundedQueue< TYPE >::removeAll (  ) 

Remove all items currently in this queue. Note that this operation is not atomic; if other threads are concurrently pushing items into the queue the result of numElements() after this function returns is not guaranteed to be 0.

template<class TYPE>
int bdlcc::BoundedQueue< TYPE >::tryPopFront ( TYPE *  value  ) 

Attempt to remove the element from the front of this queue without blocking, and, if successful, load the specified value with the removed element. Return 0 on success, and a non-zero value otherwise. Specifically, return e_SUCCESS on success, e_DISABLED if isPopFrontDisabled(), e_EMPTY if !isPopFrontDisabled() and the queue was empty, and e_FAILED if an error occurs. On failure, value is not changed.

template<class TYPE>
int bdlcc::BoundedQueue< TYPE >::tryPushBack ( const TYPE &  value  ) 

Append the specified value to the back of this queue. Return 0 on success, and a non-zero value otherwise. Specifically, return e_SUCCESS on success, e_DISABLED if isPushBackDisabled(), e_FULL if !isPushBackDisabled() and the queue was full, and e_FAILED if an error occurs.

template<class TYPE>
int bdlcc::BoundedQueue< TYPE >::tryPushBack ( bslmf::MovableRef< TYPE >  value  ) 

Append the specified move-insertable value to the back of this queue. value is left in a valid but unspecified state. Return 0 on success, and a non-zero value otherwise. Specifically, return e_SUCCESS on success, e_DISABLED if isPushBackDisabled(), e_FULL if !isPushBackDisabled() and the queue was full, and e_FAILED if an error occurs. On failure, value is not changed.

template<class TYPE>
void bdlcc::BoundedQueue< TYPE >::disablePopFront (  ) 

Disable dequeueing from this queue. All subsequent invocations of popFront or tryPopFront will fail immediately. All blocked invocations of popFront and waitUntilEmpty will fail immediately. If the queue is already dequeue disabled, this method has no effect.

template<class TYPE>
void bdlcc::BoundedQueue< TYPE >::disablePushBack (  ) 

Disable enqueueing into this queue. All subsequent invocations of pushBack or tryPushBack will fail immediately. All blocked invocations of pushBack will fail immediately. If the queue is already enqueue disabled, this method has no effect.

template<class TYPE>
void bdlcc::BoundedQueue< TYPE >::enablePopFront (  ) 

Enable dequeueing. If the queue is not dequeue disabled, this call has no effect.

template<class TYPE>
void bdlcc::BoundedQueue< TYPE >::enablePushBack (  ) 

Enable queuing. If the queue is not enqueue disabled, this call has no effect.

template<class TYPE>
bsl::size_t bdlcc::BoundedQueue< TYPE >::capacity (  )  const

Return the maximum number of elements that may be stored in this queue. Note that the value returned may be greater than that supplied at construction.

template<class TYPE>
bool bdlcc::BoundedQueue< TYPE >::isEmpty (  )  const

Return true if this queue is empty (has no elements), or false otherwise.

template<class TYPE>
bool bdlcc::BoundedQueue< TYPE >::isFull (  )  const

Return true if this queue is full (has no available capacity), or false otherwise. Note that for unbounded queues, this method always returns false.

template<class TYPE>
bool bdlcc::BoundedQueue< TYPE >::isPopFrontDisabled (  )  const

Return true if this queue is dequeue disabled, and false otherwise. Note that the queue is created in the "dequeue enabled" state.

template<class TYPE>
bool bdlcc::BoundedQueue< TYPE >::isPushBackDisabled (  )  const

Return true if this queue is enqueue disabled, and false otherwise. Note that the queue is created in the "enqueue enabled" state.

template<class TYPE>
bsl::size_t bdlcc::BoundedQueue< TYPE >::numElements (  )  const

Returns the number of elements currently in this queue. Note that numElements() == capacity() is not a valid replacement for isFull (see Exception Safety for details).

template<class TYPE>
int bdlcc::BoundedQueue< TYPE >::waitUntilEmpty (  )  const

Block until all the elements in this queue are removed. Return 0 on success, and a non-zero value otherwise. Specifically, return e_SUCCESS on success, e_DISABLED if !isEmpty() && isPopFrontDisabled(). A blocked thread waiting for the queue to empty will return e_DISABLED if disablePopFront is invoked.

template<class TYPE>
bslma::Allocator* bdlcc::BoundedQueue< TYPE >::allocator (  )  const

Return the allocator used by this object to supply memory.


Friends And Related Function Documentation

template<class TYPE>
friend class BoundedQueue_PopCompleteGuard< BoundedQueue< TYPE >,typename BoundedQueue< TYPE >::Node > [friend]
template<class TYPE>
friend class BoundedQueue_PushExceptionCompleteProctor< BoundedQueue< TYPE > > [friend]

The documentation for this class was generated from the following file: