Audacity 3.2.0
Typedefs | Enumerations | Functions
Zix

Typedefs

typedef int(* ZixComparator) (const void *a, const void *b, void *user_data)
 
typedef bool(* ZixEqualFunc) (const void *a, const void *b)
 
typedef void(* ZixDestroyFunc) (void *ptr)
 

Enumerations

enum  ZixStatus {
  ZIX_STATUS_SUCCESS , ZIX_STATUS_ERROR , ZIX_STATUS_NO_MEM , ZIX_STATUS_NOT_FOUND ,
  ZIX_STATUS_EXISTS , ZIX_STATUS_BAD_ARG , ZIX_STATUS_BAD_PERMS
}
 

Functions

static const char * zix_strerror (const ZixStatus status)
 

Ring

typedef struct ZixRingImpl ZixRing
 
ZixRingzix_ring_new (uint32_t size)
 
void zix_ring_free (ZixRing *ring)
 
void zix_ring_mlock (ZixRing *ring)
 
void zix_ring_reset (ZixRing *ring)
 
uint32_t zix_ring_read_space (const ZixRing *ring)
 
uint32_t zix_ring_write_space (const ZixRing *ring)
 
uint32_t zix_ring_capacity (const ZixRing *ring)
 
uint32_t zix_ring_peek (ZixRing *ring, void *dst, uint32_t size)
 
uint32_t zix_ring_read (ZixRing *ring, void *dst, uint32_t size)
 
uint32_t zix_ring_skip (ZixRing *ring, uint32_t size)
 
uint32_t zix_ring_write (ZixRing *ring, const void *src, uint32_t size)
 

Detailed Description

Typedef Documentation

◆ ZixComparator

typedef int(* ZixComparator) (const void *a, const void *b, void *user_data)

Function for comparing two elements.

Definition at line 83 of file common.h.

◆ ZixDestroyFunc

typedef void(* ZixDestroyFunc) (void *ptr)

Function to destroy an element.

Definition at line 93 of file common.h.

◆ ZixEqualFunc

typedef bool(* ZixEqualFunc) (const void *a, const void *b)

Function for testing equality of two elements.

Definition at line 88 of file common.h.

◆ ZixRing

typedef struct ZixRingImpl ZixRing

A lock-free ring buffer.

Thread-safe with a single reader and single writer, and realtime safe on both ends.

Definition at line 41 of file ring.h.

Enumeration Type Documentation

◆ ZixStatus

enum ZixStatus
Enumerator
ZIX_STATUS_SUCCESS 
ZIX_STATUS_ERROR 
ZIX_STATUS_NO_MEM 
ZIX_STATUS_NOT_FOUND 
ZIX_STATUS_EXISTS 
ZIX_STATUS_BAD_ARG 
ZIX_STATUS_BAD_PERMS 

Definition at line 55 of file common.h.

55 {
63} ZixStatus;
ZixStatus
Definition: common.h:55
@ ZIX_STATUS_EXISTS
Definition: common.h:60
@ ZIX_STATUS_BAD_ARG
Definition: common.h:61
@ ZIX_STATUS_NOT_FOUND
Definition: common.h:59
@ ZIX_STATUS_ERROR
Definition: common.h:57
@ ZIX_STATUS_NO_MEM
Definition: common.h:58
@ ZIX_STATUS_SUCCESS
Definition: common.h:56
@ ZIX_STATUS_BAD_PERMS
Definition: common.h:62

Function Documentation

◆ zix_ring_capacity()

uint32_t zix_ring_capacity ( const ZixRing ring)

Return the capacity (i.e. total write space when empty).

Definition at line 141 of file ring.cpp.

142{
143 return ring->size - 1;
144}
uint32_t size
Size (capacity) in bytes.
Definition: ring.cpp:54

References ZixRingImpl::size.

◆ zix_ring_free()

void zix_ring_free ( ZixRing ring)

Destroy a ring.

Definition at line 86 of file ring.cpp.

87{
88 free(ring->buf);
89 free(ring);
90}
void free(void *ptr)
Definition: VectorOps.h:34
char * buf
Contents.
Definition: ring.cpp:56

References ZixRingImpl::buf, and staffpad::vo::free().

Here is the call graph for this function:

◆ zix_ring_mlock()

void zix_ring_mlock ( ZixRing ring)

Lock the ring data into physical memory.

This function is NOT thread safe or real-time safe, but it should be called after zix_ring_new() to lock all ring memory to avoid page faults while using the ring (i.e. this function MUST be called first in order for the ring to be truly real-time safe).

Definition at line 93 of file ring.cpp.

94{
95 ZIX_MLOCK(ring, sizeof(ZixRing));
96 ZIX_MLOCK(ring->buf, ring->size);
97}
#define ZIX_MLOCK(ptr, size)
Definition: ring.cpp:29

References ZixRingImpl::buf, ZixRingImpl::size, and ZIX_MLOCK.

Referenced by LV2AtomPortState::LV2AtomPortState().

Here is the caller graph for this function:

◆ zix_ring_new()

ZixRing * zix_ring_new ( uint32_t  size)

Create a new ring.

Parameters
sizeSize in bytes (note this may be rounded up).

At most size - 1 bytes may be stored in the ring at once.

Definition at line 74 of file ring.cpp.

75{
76 ZixRing* ring = (ZixRing*)malloc(sizeof(ZixRing));
77 ring->write_head = 0;
78 ring->read_head = 0;
80 ring->size_mask = ring->size - 1;
81 ring->buf = (char*)malloc(ring->size);
82 return ring;
83}
static uint32_t next_power_of_two(uint32_t size)
Definition: ring.cpp:60
uint32_t read_head
Write index into buf.
Definition: ring.cpp:53
uint32_t size_mask
Mask for fast modulo.
Definition: ring.cpp:55
uint32_t write_head
Read index into buf.
Definition: ring.cpp:52

References ZixRingImpl::buf, next_power_of_two(), ZixRingImpl::read_head, ZixRingImpl::size, size, ZixRingImpl::size_mask, and ZixRingImpl::write_head.

Here is the call graph for this function:

◆ zix_ring_peek()

uint32_t zix_ring_peek ( ZixRing ring,
void *  dst,
uint32_t  size 
)

Read from the ring without advancing the read head.

Definition at line 166 of file ring.cpp.

167{
168 return peek_internal(ring, ring->read_head, ring->write_head, size, dst);
169}
static uint32_t peek_internal(const ZixRing *ring, uint32_t r, uint32_t w, uint32_t size, void *dst)
Definition: ring.cpp:147

References peek_internal(), ZixRingImpl::read_head, size, and ZixRingImpl::write_head.

Here is the call graph for this function:

◆ zix_ring_read()

uint32_t zix_ring_read ( ZixRing ring,
void *  dst,
uint32_t  size 
)

Read from the ring and advance the read head.

Definition at line 172 of file ring.cpp.

173{
174 const uint32_t r = ring->read_head;
175 const uint32_t w = ring->write_head;
176
177 if (peek_internal(ring, r, w, size, dst)) {
179 ring->read_head = (r + size) & ring->size_mask;
180 return size;
181 } else {
182 return 0;
183 }
184}
#define ZIX_READ_BARRIER()
Definition: ring.cpp:46

References peek_internal(), ZixRingImpl::read_head, size, ZixRingImpl::size_mask, ZixRingImpl::write_head, and ZIX_READ_BARRIER.

Referenced by LV2AtomPortState::SendToDialog(), and LV2AtomPortState::SendToInstance().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ zix_ring_read_space()

uint32_t zix_ring_read_space ( const ZixRing ring)

Return the number of bytes of space available for reading.

Definition at line 117 of file ring.cpp.

118{
119 return read_space_internal(ring, ring->read_head, ring->write_head);
120}
static uint32_t read_space_internal(const ZixRing *ring, uint32_t r, uint32_t w)
Definition: ring.cpp:107

References ZixRingImpl::read_head, read_space_internal(), and ZixRingImpl::write_head.

Here is the call graph for this function:

◆ zix_ring_reset()

void zix_ring_reset ( ZixRing ring)

Reset (empty) a ring.

This function is NOT thread-safe, it may only be called when there are no readers or writers.

Definition at line 100 of file ring.cpp.

101{
102 ring->write_head = 0;
103 ring->read_head = 0;
104}

References ZixRingImpl::read_head, and ZixRingImpl::write_head.

◆ zix_ring_skip()

uint32_t zix_ring_skip ( ZixRing ring,
uint32_t  size 
)

Skip data in the ring (advance read head without reading).

Definition at line 187 of file ring.cpp.

188{
189 const uint32_t r = ring->read_head;
190 const uint32_t w = ring->write_head;
191 if (read_space_internal(ring, r, w) < size) {
192 return 0;
193 }
194
196 ring->read_head = (r + size) & ring->size_mask;
197 return size;
198}

References ZixRingImpl::read_head, read_space_internal(), size, ZixRingImpl::size_mask, ZixRingImpl::write_head, and ZIX_READ_BARRIER.

Referenced by LV2AtomPortState::SendToDialog(), and LV2AtomPortState::SendToInstance().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ zix_ring_write()

uint32_t zix_ring_write ( ZixRing ring,
const void *  src,
uint32_t  size 
)

Write data to the ring.

Definition at line 201 of file ring.cpp.

202{
203 const uint32_t r = ring->read_head;
204 const uint32_t w = ring->write_head;
205 if (write_space_internal(ring, r, w) < size) {
206 return 0;
207 }
208
209 if (w + size <= ring->size) {
210 memcpy(&ring->buf[w], src, size);
212 ring->write_head = (w + size) & ring->size_mask;
213 } else {
214 const uint32_t this_size = ring->size - w;
215 memcpy(&ring->buf[w], src, this_size);
216 memcpy(&ring->buf[0], (const char*)src + this_size, size - this_size);
218 ring->write_head = size - this_size;
219 }
220
221 return size;
222}
#define ZIX_WRITE_BARRIER()
Definition: ring.cpp:47
static uint32_t write_space_internal(const ZixRing *ring, uint32_t r, uint32_t w)
Definition: ring.cpp:123

References ZixRingImpl::buf, ZixRingImpl::read_head, ZixRingImpl::size, size, ZixRingImpl::size_mask, ZixRingImpl::write_head, write_space_internal(), and ZIX_WRITE_BARRIER.

Referenced by LV2AtomPortState::ReceiveFromDialog(), and LV2AtomPortState::ReceiveFromInstance().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ zix_ring_write_space()

uint32_t zix_ring_write_space ( const ZixRing ring)

Return the number of bytes of space available for writing.

Definition at line 135 of file ring.cpp.

136{
137 return write_space_internal(ring, ring->read_head, ring->write_head);
138}

References ZixRingImpl::read_head, ZixRingImpl::write_head, and write_space_internal().

Here is the call graph for this function:

◆ zix_strerror()

static const char * zix_strerror ( const ZixStatus  status)
inlinestatic

Definition at line 66 of file common.h.

67{
68 switch (status) {
69 case ZIX_STATUS_SUCCESS: return "Success";
70 case ZIX_STATUS_ERROR: return "Unknown error";
71 case ZIX_STATUS_NO_MEM: return "Out of memory";
72 case ZIX_STATUS_NOT_FOUND: return "Not found";
73 case ZIX_STATUS_EXISTS: return "Exists";
74 case ZIX_STATUS_BAD_ARG: return "Bad argument";
75 case ZIX_STATUS_BAD_PERMS: return "Bad permissions";
76 }
77 return "Unknown error";
78}

References ZIX_STATUS_BAD_ARG, ZIX_STATUS_BAD_PERMS, ZIX_STATUS_ERROR, ZIX_STATUS_EXISTS, ZIX_STATUS_NO_MEM, ZIX_STATUS_NOT_FOUND, and ZIX_STATUS_SUCCESS.