Jetson Inference
DNN Vision Library

Thread-safe circular ring buffer queue. More...

#include <RingBuffer.h>

Public Types

enum  Flags {
  Read = (1 << 0), ReadOnce = (1 << 1) | Read, ReadLatest = (1 << 2) | Read, ReadLatestOnce = (1 << 3) | ReadLatest,
  Write = (1 << 4), Threaded = (1 << 5), ZeroCopy = (1 << 6)
}
 Ring buffer flags. More...
 

Public Member Functions

 RingBuffer (uint32_t flags=Threaded)
 Construct a new ring buffer. More...
 
 ~RingBuffer ()
 Destructor. More...
 
bool Alloc (uint32_t numBuffers, size_t size, uint32_t flags=0)
 Allocate memory for a set of buffers, where each buffer has the specified size. More...
 
void Free ()
 Free the buffer allocations. More...
 
void * Peek (uint32_t flags)
 Get the next read/write buffer without advancing the position in the queue. More...
 
void * Next (uint32_t flags)
 Get the next read/write buffer and advance the position in the queue. More...
 
uint32_t GetFlags () const
 Get the flags of the ring buffer. More...
 
void SetFlags (uint32_t flags)
 Set the ring buffer's flags. More...
 
void SetThreaded (bool threaded)
 Enable or disable multi-threading. More...
 

Protected Attributes

uint32_t mNumBuffers
 
uint32_t mLatestRead
 
uint32_t mLatestWrite
 
uint32_t mFlags
 
void ** mBuffers
 
size_t mBufferSize
 
bool mReadOnce
 
Mutex mMutex
 

Detailed Description

Thread-safe circular ring buffer queue.

Member Enumeration Documentation

◆ Flags

Ring buffer flags.

Enumerator
Read 

Read the next buffer.

ReadOnce 

Read the next buffer, but only if it hasn't been read before.

ReadLatest 

Read the latest buffer in the queue, skipping other buffers that may not have been read.

ReadLatestOnce 

Combination of ReadOnce and ReadLatest flags.

Write 

Write the next buffer.

Threaded 

Buffers should be thread-safe (enabled by default).

ZeroCopy 

Buffers should be allocated in mapped CPU/GPU zeroCopy memory (otherwise GPU only)

Constructor & Destructor Documentation

◆ RingBuffer()

RingBuffer::RingBuffer ( uint32_t  flags = Threaded)
inline

Construct a new ring buffer.

◆ ~RingBuffer()

RingBuffer::~RingBuffer ( )
inline

Destructor.

Member Function Documentation

◆ Alloc()

bool RingBuffer::Alloc ( uint32_t  numBuffers,
size_t  size,
uint32_t  flags = 0 
)
inline

Allocate memory for a set of buffers, where each buffer has the specified size.

If the requested allocation is compatible with what was already allocated, this will return true without performing additional allocations. Otherwise, the previous buffers are released and new ones are allocated.

Returns
true if the allocations succeeded or was previously done. false if a memory allocation error occurred.

◆ Free()

void RingBuffer::Free ( )
inline

Free the buffer allocations.

◆ GetFlags()

uint32_t RingBuffer::GetFlags ( ) const
inline

Get the flags of the ring buffer.

◆ Next()

void* RingBuffer::Next ( uint32_t  flags)
inline

Get the next read/write buffer and advance the position in the queue.

◆ Peek()

void* RingBuffer::Peek ( uint32_t  flags)
inline

Get the next read/write buffer without advancing the position in the queue.

◆ SetFlags()

void RingBuffer::SetFlags ( uint32_t  flags)
inline

Set the ring buffer's flags.

◆ SetThreaded()

void RingBuffer::SetThreaded ( bool  threaded)
inline

Enable or disable multi-threading.

Member Data Documentation

◆ mBuffers

void** RingBuffer::mBuffers
protected

◆ mBufferSize

size_t RingBuffer::mBufferSize
protected

◆ mFlags

uint32_t RingBuffer::mFlags
protected

◆ mLatestRead

uint32_t RingBuffer::mLatestRead
protected

◆ mLatestWrite

uint32_t RingBuffer::mLatestWrite
protected

◆ mMutex

Mutex RingBuffer::mMutex
protected

◆ mNumBuffers

uint32_t RingBuffer::mNumBuffers
protected

◆ mReadOnce

bool RingBuffer::mReadOnce
protected

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