PConcurrentRawBufferQueue Class Reference

Detailed Description

The PConcurrentRawBufferQueue class represents a concurrent bounded queue of raw buffers, thread-safe.

The class is thread-safe and ready for concurrency. Buffers are re-used. Once the maximum capacity has been reached, then no more memory allocation is performed.

Definition at line 28 of file PConcurrentRawBufferQueue.h.

#include <PConcurrentRawBufferQueue.h>

Constructor & Destructor Documentation

◆ PConcurrentRawBufferQueue() [1/2]

PConcurrentRawBufferQueue::PConcurrentRawBufferQueue ( papillon::int32  capacity,
papillon::int32  sizeOfBuffersInBytes 
)
explicit

Constructs an empty queue of raw buffers with the specified capacity.

All buffers have the same size (sizeOfBuffersInBytes). Warning:

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

◆ PConcurrentRawBufferQueue() [2/2]

PConcurrentRawBufferQueue::PConcurrentRawBufferQueue ( const PConcurrentRawBufferQueue other)

Constructs a shared copy of other.

◆ ~PConcurrentRawBufferQueue()

virtual PConcurrentRawBufferQueue::~PConcurrentRawBufferQueue ( )
virtual

Destroys this object.

Member Function Documentation

◆ Clear()

void PConcurrentRawBufferQueue::Clear ( )

Removes all the elements from this queue.

After this method, the queue is empty.

See also
IsEmpty

◆ DropOldest()

void PConcurrentRawBufferQueue::DropOldest ( )

Removes the oldest enqueued buffer if possible.

Decreases the size of this queue of 1.

◆ Enqueue()

void PConcurrentRawBufferQueue::Enqueue ( const void *  sourceBuffer)

Enqueues the specified source buffer (performs a copy).

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

◆ GetCapacity()

papillon::int32 PConcurrentRawBufferQueue::GetCapacity ( ) const

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

◆ IsEmpty()

bool PConcurrentRawBufferQueue::IsEmpty ( )

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

◆ IsFull()

bool PConcurrentRawBufferQueue::IsFull ( )

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

See also
DropOldest

◆ operator=()

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

Performs a shared copy of other to this object.

◆ ResizeBuffers()

void PConcurrentRawBufferQueue::ResizeBuffers ( papillon::int32  newSizeOfBuffers)

Resizes the buffers used by this queue.

The queue is first cleared. After this method, the queue will be empty. newSizeOfBuffers must be 1 at least (will be forced to 1 if <= 0).

◆ Size()

papillon::int32 PConcurrentRawBufferQueue::Size ( )

Returns the current number of pending buffers to dequeue.

◆ TryDequeue()

PResult PConcurrentRawBufferQueue::TryDequeue ( void *  destinationBuffer,
int32  timeOutMs = -1 
)

Dequeues a buffer and copy it to destinationBuffer 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 available buffer in the queue.

See also
TryEnqueue
IsEmpty

◆ TryEnqueue()

PResult PConcurrentRawBufferQueue::TryEnqueue ( const void *  sourceBuffer,
int32  timeOutMs = -1 
)

Enqueues the specified source buffer (performs a copy) 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 free buffer is available.

See also
TryDequeue
IsFull
DropOldest