BDE 4.14.0 Production release
|
#include <bdlcc_fixedqueue.h>
Public Member Functions | |
BSLMF_NESTED_TRAIT_DECLARATION (FixedQueue, bslma::UsesBslmaAllocator) | |
FixedQueue (bsl::size_t capacity, bslma::Allocator *basicAllocator=0) | |
~FixedQueue () | |
Destroy this object. | |
int | pushBack (const TYPE &value) |
int | pushBack (bslmf::MovableRef< TYPE > value) |
int | tryPushBack (const TYPE &value) |
int | tryPushBack (bslmf::MovableRef< TYPE > value) |
void | popFront (TYPE *value) |
TYPE | popFront () |
int | tryPopFront (TYPE *value) |
void | removeAll () |
void | disable () |
void | enable () |
int | capacity () const |
bool | isEmpty () const |
bool | isEnabled () const |
bool | isFull () const |
int | numElements () const |
Returns the number of elements currently in this queue. | |
int | length () const |
[DEPRECATED] Invoke numElements . | |
int | size () const |
[DEPRECATED] Invoke capacity . | |
Friends | |
template<class VAL > | |
class | FixedQueue_PushProctor |
template<class VAL > | |
class | FixedQueue_PopGuard |
This class provides a thread-aware, lock-free, fixed-size queue of values.
See bdlcc_fixedqueue
|
explicit |
Create a thread-aware lock-free queue having the specified capacity
. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used. The behavior is undefined unless 0 < capacity
and capacity <= bdlcc::FixedQueueIndexManager::k_MAX_CAPACITY
.
bdlcc::FixedQueue< TYPE >::~FixedQueue | ( | ) |
bdlcc::FixedQueue< TYPE >::BSLMF_NESTED_TRAIT_DECLARATION | ( | FixedQueue< TYPE > | , |
bslma::UsesBslmaAllocator | |||
) |
|
inline |
Return the maximum number of elements that may be stored in this queue.
void bdlcc::FixedQueue< TYPE >::disable | ( | ) |
Disable 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 disabled, this method has no effect.
|
inline |
Enable queuing. If the queue is not disabled, this call has no effect.
|
inline |
Return true
if this queue is empty (has no elements), or false
otherwise.
|
inline |
Return true
if this queue is enabled, and false
otherwise. Note that the queue is created in the "enabled" state.
|
inline |
Return true
if this queue is full (when the number of elements currently in this queue equals its capacity), or false
otherwise.
|
inline |
|
inline |
TYPE bdlcc::FixedQueue< TYPE >::popFront | ( | ) |
Remove the element from the front of this queue and return it's value. If the queue is empty, block until it is not empty.
void bdlcc::FixedQueue< 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.
int bdlcc::FixedQueue< TYPE >::pushBack | ( | bslmf::MovableRef< TYPE > | value | ) |
Append the specified move-insertable value
to the back of this queue, blocking until either space is available - if necessary - or the queue is disabled. value
is left in a valid but unspecified state. Return 0 on success, and a nonzero value if the queue is disabled.
int bdlcc::FixedQueue< TYPE >::pushBack | ( | const TYPE & | value | ) |
Append the specified value
to the back of this queue, blocking until either space is available - if necessary - or the queue is disabled. Return 0 on success, and a nonzero value if the queue is disabled.
void bdlcc::FixedQueue< TYPE >::removeAll | ( | ) |
Remove all items from 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.
|
inline |
int bdlcc::FixedQueue< 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 if queue was empty. On failure, value
is not changed.
int bdlcc::FixedQueue< TYPE >::tryPushBack | ( | bslmf::MovableRef< TYPE > | value | ) |
Attempt to append the specified move-insertable value
to the back of this queue without blocking. value
is left in a valid but unspecified state. Return 0 on success, and a non-zero value if the queue is full or disabled.
int bdlcc::FixedQueue< TYPE >::tryPushBack | ( | const TYPE & | value | ) |
Attempt to append the specified value
to the back of this queue without blocking. Return 0 on success, and a non-zero value if the queue is full or disabled.