#include <stdbool.h>
#include <string.h>
#include <assert.h>
#include <stdatomic.h>
Go to the source code of this file.
Class Members |
void * |
buffer |
|
int32_t |
length |
|
int32_t |
tail |
|
int32_t |
head |
|
volatile atomic_int |
fillCount |
|
bool |
atomic |
|
Initialise buffer.
Note that the length is advisory only: Because of the way the memory mirroring technique works, the true buffer length will be multiples of the device page size (e.g. 4096 bytes)
If you intend to use the AudioBufferList utilities, you should always allocate a bit more space than you need for pure audio data, so there's room for the metadata. How much extra is required depends on how many AudioBufferList structures are used, which is a function of how many audio frames each buffer holds. A good rule of thumb is to add 15%, or at least another 2048 bytes or so.
- Parameters
-
buffer | Circular buffer |
length | Length of buffer |
bool _TPCircularBufferInit |
( |
TPCircularBuffer * |
buffer, |
|
|
int32_t |
length, |
|
|
size_t |
structSize |
|
) |
| |
Cleanup buffer.
Releases buffer resources.
Clear buffer.
Resets buffer to original, empty state.
This is safe for use by consumer while producer is accessing buffer.
Set the atomicity.
If you set the atomiticy to false using this method, the buffer will not use atomic operations. This can be used to give the compiler a little more optimisation opportunities when the buffer is only used on one thread.
Important note: Only set this to false if you know what you're doing!
The default value is true (the buffer will use atomic operations)
- Parameters
-
buffer | Circular buffer |
atomic | Whether the buffer is atomic (default true) |
return |
( |
void * |
| ) |
-> buffer+buffer->tail) |
TPCircularBufferProduce |
( |
buffer |
, |
|
|
len |
|
|
) |
| |
static __inline__ int32_t * availableBytes |
static __inline__ int32_t amount |
Initial value:{
buffer->tail = (buffer->tail +
amount) % buffer->length
__inline__ const void* src |
__inline__ const void int32_t len |
void* ptr = TPCircularBufferHead(buffer, &space) |