BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlcc::SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION > Class Template Reference

#include <bdlcc_singleconsumerqueueimpl.h>

Public Types

enum  { e_SUCCESS = 0 , e_EMPTY = -1 , e_DISABLED = -2 }
 
typedef TYPE value_type
 

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (SingleConsumerQueueImpl, bslma::UsesBslmaAllocator)
 
 SingleConsumerQueueImpl (bslma::Allocator *basicAllocator=0)
 
 SingleConsumerQueueImpl (bsl::size_t capacity, bslma::Allocator *basicAllocator=0)
 
 ~SingleConsumerQueueImpl ()
 
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 ()
 
bool isEmpty () const
 
bool isFull () const
 
bool isPopFrontDisabled () const
 
bool isPushBackDisabled () const
 
bsl::size_t numElements () const
 Returns the number of elements currently in this queue.
 
int waitUntilEmpty () const
 
bslma::Allocatorallocator () const
 Return the allocator used by this object to supply memory.
 

Friends

class SingleConsumerQueueImpl_MarkReclaimProctor< SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >, typename SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::Node >
 
class SingleConsumerQueueImpl_PopCompleteGuard< SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION > >
 
class SingleConsumerQueueImpl_AllocateLockGuard< SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION > >
 

Detailed Description

template<class TYPE, class ATOMIC_OP, class MUTEX, class CONDITION>
class bdlcc::SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >

This class provides a thread-safe unbounded queue of values that assumes a single consumer thread.

The types ATOMIC_OP, MUTEX, and CONDITION are exposed for testing. Typical usage is with bsls::AtomicOperations for ATOMIC_OP, bslmt::Mutex for MUTEX, and bslmt::Condition for CONDITION.

See bdlcc_singleconsumerqueueimpl

Member Typedef Documentation

◆ value_type

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
typedef TYPE bdlcc::SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::value_type

Member Enumeration Documentation

◆ anonymous enum

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
anonymous enum
Enumerator
e_SUCCESS 
e_EMPTY 
e_DISABLED 

Constructor & Destructor Documentation

◆ SingleConsumerQueueImpl() [1/2]

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
bdlcc::SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::SingleConsumerQueueImpl ( bslma::Allocator basicAllocator = 0)
explicit

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

◆ SingleConsumerQueueImpl() [2/2]

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
bdlcc::SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::SingleConsumerQueueImpl ( 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.

◆ ~SingleConsumerQueueImpl()

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
bdlcc::SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::~SingleConsumerQueueImpl ( )

Destroy this container. The behavior is undefined unless all access or modification of the container has completed prior to this call.

Member Function Documentation

◆ allocator()

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
bslma::Allocator * bdlcc::SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::allocator ( ) const

◆ BSLMF_NESTED_TRAIT_DECLARATION()

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
bdlcc::SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::BSLMF_NESTED_TRAIT_DECLARATION ( SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >  ,
bslma::UsesBslmaAllocator   
)

◆ disablePopFront()

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
void bdlcc::SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::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.

◆ disablePushBack()

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
void bdlcc::SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::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.

◆ enablePopFront()

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
void bdlcc::SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::enablePopFront ( )

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

◆ enablePushBack()

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
void bdlcc::SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::enablePushBack ( )

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

◆ isEmpty()

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
bool bdlcc::SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::isEmpty ( ) const

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

◆ isFull()

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
bool bdlcc::SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::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.

◆ isPopFrontDisabled()

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
bool bdlcc::SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::isPopFrontDisabled ( ) const

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

◆ isPushBackDisabled()

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
bool bdlcc::SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::isPushBackDisabled ( ) const

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

◆ numElements()

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
bsl::size_t bdlcc::SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::numElements ( ) const

◆ popFront()

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
int bdlcc::SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::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_DISABLED if isPopFrontDisabled(). On failure, value is not changed. Threads blocked due to the queue being empty will return e_DISABLED if disablePopFront is invoked. The behavior is undefined unless the invoker of this method is the single consumer.

◆ pushBack() [1/2]

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
int bdlcc::SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::pushBack ( 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_DISABLED if isPushBackDisabled(). On failure, value is not changed.

◆ pushBack() [2/2]

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
int bdlcc::SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::pushBack ( 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_DISABLED if isPushBackDisabled().

◆ removeAll()

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
void bdlcc::SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::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. The behavior is undefined unless the invoker of this method is the single consumer.

◆ tryPopFront()

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
int bdlcc::SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::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_DISABLED if isPopFrontDisabled(), and e_EMPTY if !isPopFrontDisabled() and the queue was empty. On failure, value is not changed. The behavior is undefined unless the invoker of this method is the single consumer.

◆ tryPushBack() [1/2]

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
int bdlcc::SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::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_DISABLED if isPushBackDisabled(). On failure, value is not changed.

◆ tryPushBack() [2/2]

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
int bdlcc::SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::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, retun e_DISABLED if isPushBackDisabled().

◆ waitUntilEmpty()

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
int bdlcc::SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::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_DISABLED if !isEmpty() && isPopFrontDisabled(). A blocked thread waiting for the queue to empty will return e_DISABLED if disablePopFront is invoked.

Friends And Related Symbol Documentation

◆ SingleConsumerQueueImpl_AllocateLockGuard< SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION > >

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
friend class SingleConsumerQueueImpl_AllocateLockGuard< SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION > >
friend

◆ SingleConsumerQueueImpl_MarkReclaimProctor< SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >, typename SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::Node >

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
friend class SingleConsumerQueueImpl_MarkReclaimProctor< SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >, typename SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION >::Node >
friend

◆ SingleConsumerQueueImpl_PopCompleteGuard< SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION > >

template<class TYPE , class ATOMIC_OP , class MUTEX , class CONDITION >
friend class SingleConsumerQueueImpl_PopCompleteGuard< SingleConsumerQueueImpl< TYPE, ATOMIC_OP, MUTEX, CONDITION > >
friend

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