docs/html/RingBuffer_8h_source.html
| | Jetson Inference
DNN Vision Library |
RingBuffer.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22
23 #ifndef __MULTITHREAD_RINGBUFFER_H_
24 #define __MULTITHREAD_RINGBUFFER_H_
25
26 #include "Mutex.h"
27
28
33 class RingBuffer
34 {
35 public:
40 {
43ReadLatest = (1 << 2) | Read,
44ReadLatestOnce = (1 << 3) | ReadLatest,
48 };
49
53inline RingBuffer( uint32_t flags=Threaded );
54
58inline ~RingBuffer();
59
70inline bool Alloc( uint32_t numBuffers, size_t size, uint32_t flags=0 );
71
75inline void Free();
76
80inline void* Peek( uint32_t flags );
81
85inline void* Next( uint32_t flags );
86
90inline uint32_t GetFlags() const;
91
95inline void SetFlags( uint32_t flags );
96
100inline void SetThreaded( bool threaded );
101
102 protected:
103
104 uint32_t mNumBuffers;
105 uint32_t mLatestRead;
106 uint32_t mLatestWrite;
108
110size_t mBufferSize;
113 };
114
115 // inline implementations
116 #include "RingBuffer.inl"
117
118 #endif
119
~RingBuffer()
Destructor.
bool mReadOnce
Definition: RingBuffer.h:111
@ Threaded
Buffers should be thread-safe (enabled by default).
Definition: RingBuffer.h:46
uint32_t mNumBuffers
Definition: RingBuffer.h:104
RingBuffer(uint32_t flags=Threaded)
Construct a new ring buffer.
@ ReadOnce
Read the next buffer, but only if it hasn't been read before.
Definition: RingBuffer.h:42
size_t mBufferSize
Definition: RingBuffer.h:110
void * Next(uint32_t flags)
Get the next read/write buffer and advance the position in the queue.
A lightweight mutual exclusion lock.
Definition: Mutex.h:35
void ** mBuffers
Definition: RingBuffer.h:109
uint32_t GetFlags() const
Get the flags of the ring buffer.
@ ReadLatest
Read the latest buffer in the queue, skipping other buffers that may not have been read.
Definition: RingBuffer.h:43
void SetFlags(uint32_t flags)
Set the ring buffer's flags.
@ Write
Write the next buffer.
Definition: RingBuffer.h:45
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.
Mutex mMutex
Definition: RingBuffer.h:112
Flags
Ring buffer flags.
Definition: RingBuffer.h:39
void SetThreaded(bool threaded)
Enable or disable multi-threading.
void Free()
Free the buffer allocations.
@ Read
Read the next buffer.
Definition: RingBuffer.h:41
Thread-safe circular ring buffer queue.
Definition: RingBuffer.h:33
@ ZeroCopy
Buffers should be allocated in mapped CPU/GPU zeroCopy memory (otherwise GPU only)
Definition: RingBuffer.h:47
uint32_t mLatestWrite
Definition: RingBuffer.h:106
@ ReadLatestOnce
Combination of ReadOnce and ReadLatest flags.
Definition: RingBuffer.h:44
uint32_t mLatestRead
Definition: RingBuffer.h:105
uint32_t mFlags
Definition: RingBuffer.h:107
void * Peek(uint32_t flags)
Get the next read/write buffer without advancing the position in the queue.