PConcurrentQueue Class Reference

Detailed Description

The PConcurrentQueue class represents a concurrent bounded queue of PObject, thread-safe.

The class is thread-safe and ready for concurrency.

Definition at line 26 of file PConcurrentQueue.h.

#include <PConcurrentQueue.h>

Constructor & Destructor Documentation

◆ PConcurrentQueue() [1/2]

PConcurrentQueue::PConcurrentQueue ( papillon::int32  capacity)
explicit

Constructs an empty queue with the specified capacity.

Warning:

  • capacity must be 1 at least (will be forced to 1 if <= 0).

◆ PConcurrentQueue() [2/2]

PConcurrentQueue::PConcurrentQueue ( const PConcurrentQueue other)

Constructs a shared copy of other.

◆ ~PConcurrentQueue()

virtual PConcurrentQueue::~PConcurrentQueue ( )
virtual

Destroys this object.

Member Function Documentation

◆ Clear()

void PConcurrentQueue::Clear ( )

Removes all the elements from this queue.

After this method, the queue is empty.

See also
IsEmpty

◆ DropOldest()

void PConcurrentQueue::DropOldest ( )

Removes the oldest enqueued element if possible.

Decreases the size of this queue of 1.

◆ Enqueue()

void PConcurrentQueue::Enqueue ( const PObject object)

Enqueues the specified object.

If the queue is full, the oldest object is dropped (enqueue is forced).

◆ GetCapacity()

papillon::int32 PConcurrentQueue::GetCapacity ( ) const

Returns the maximum number of elements that can be stored in this queue.

◆ IsEmpty()

bool PConcurrentQueue::IsEmpty ( ) const

Returns true if and only if this queue is empty (no element to dequeue), false otherwise.

◆ IsFull()

bool PConcurrentQueue::IsFull ( ) const

Returns true if and only if this queue is full (unable to enqueue a new element), false otherwise.

See also
DropOldest

◆ operator=()

PConcurrentQueue& PConcurrentQueue::operator= ( const PConcurrentQueue other)

Performs a shared copy of other to this object.

◆ SetCapacity()

void PConcurrentQueue::SetCapacity ( papillon::int32  capacity)

Sets the maximum number of elements that can be stored in this queue.

If the current number of elements exceeds the new capacity, then oldest elements are dropped. Capacity is forced to be greater or equal to 1.

◆ Size()

papillon::int32 PConcurrentQueue::Size ( ) const

Returns the current number of pending elements to dequeue.

◆ TryDequeue()

PResult PConcurrentQueue::TryDequeue ( PObject destObject,
int32  timeOutMs = -1 
)

Dequeues an object and copy it to destObject if the queue is not empty.

If the queue is empty, wait up to timeOutMs milliseconds. Returns PResult::C_OK if success, another result otherwise.

By default timeOutMs is -1: the operation is blocking and waits indefinitely until an element is available in the queue.

See also
TryEnqueue
IsEmpty

◆ TryEnqueue()

PResult PConcurrentQueue::TryEnqueue ( const PObject object,
int32  timeOutMs = -1 
)

Enqueues the specified object if the queue is not full.

If the queue is full, wait up to timeOutMs milliseconds. Returns PResult::C_OK if success, another result otherwise.

By default timeOutMs is -1: the operation is blocking and waits indefinitely until a slot is available.

See also
TryDequeue
IsFull
DropOldest