Audacity 3.2.0
Classes | Macros | Functions
ring.cpp File Reference
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "ring.h"
Include dependency graph for ring.cpp:

Go to the source code of this file.

Classes

struct  ZixRingImpl
 

Macros

#define ZIX_MLOCK(ptr, size)
 
#define ZIX_FULL_BARRIER()
 
#define ZIX_READ_BARRIER()   ZIX_FULL_BARRIER()
 
#define ZIX_WRITE_BARRIER()   ZIX_FULL_BARRIER()
 

Functions

static uint32_t next_power_of_two (uint32_t size)
 
ZixRingzix_ring_new (uint32_t size)
 
void zix_ring_free (ZixRing *ring)
 
void zix_ring_mlock (ZixRing *ring)
 
void zix_ring_reset (ZixRing *ring)
 
static uint32_t read_space_internal (const ZixRing *ring, uint32_t r, uint32_t w)
 
uint32_t zix_ring_read_space (const ZixRing *ring)
 
static uint32_t write_space_internal (const ZixRing *ring, uint32_t r, uint32_t w)
 
uint32_t zix_ring_write_space (const ZixRing *ring)
 
uint32_t zix_ring_capacity (const ZixRing *ring)
 
static uint32_t peek_internal (const ZixRing *ring, uint32_t r, uint32_t w, uint32_t size, void *dst)
 
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)
 

Macro Definition Documentation

◆ ZIX_FULL_BARRIER

#define ZIX_FULL_BARRIER ( )

Definition at line 42 of file ring.cpp.

◆ ZIX_MLOCK

#define ZIX_MLOCK (   ptr,
  size 
)

Definition at line 29 of file ring.cpp.

◆ ZIX_READ_BARRIER

#define ZIX_READ_BARRIER ( )    ZIX_FULL_BARRIER()

Definition at line 46 of file ring.cpp.

◆ ZIX_WRITE_BARRIER

#define ZIX_WRITE_BARRIER ( )    ZIX_FULL_BARRIER()

Definition at line 47 of file ring.cpp.

Function Documentation

◆ next_power_of_two()

static uint32_t next_power_of_two ( uint32_t  size)
inlinestatic

Definition at line 60 of file ring.cpp.

61{
62 // http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
63 size--;
64 size |= size >> 1;
65 size |= size >> 2;
66 size |= size >> 4;
67 size |= size >> 8;
68 size |= size >> 16;
69 size++;
70 return size;
71}

References size.

Referenced by zix_ring_new().

Here is the caller graph for this function:

◆ peek_internal()

static uint32_t peek_internal ( const ZixRing ring,
uint32_t  r,
uint32_t  w,
uint32_t  size,
void *  dst 
)
inlinestatic

Definition at line 147 of file ring.cpp.

149{
150 if (read_space_internal(ring, r, w) < size) {
151 return 0;
152 }
153
154 if (r + size < ring->size) {
155 memcpy(dst, &ring->buf[r], size);
156 } else {
157 const uint32_t first_size = ring->size - r;
158 memcpy(dst, &ring->buf[r], first_size);
159 memcpy((char*)dst + first_size, &ring->buf[0], size - first_size);
160 }
161
162 return size;
163}
static uint32_t read_space_internal(const ZixRing *ring, uint32_t r, uint32_t w)
Definition: ring.cpp:107
uint32_t size
Size (capacity) in bytes.
Definition: ring.cpp:54
char * buf
Contents.
Definition: ring.cpp:56

References ZixRingImpl::buf, read_space_internal(), ZixRingImpl::size, and size.

Referenced by zix_ring_peek(), and zix_ring_read().

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

◆ read_space_internal()

static uint32_t read_space_internal ( const ZixRing ring,
uint32_t  r,
uint32_t  w 
)
inlinestatic

Definition at line 107 of file ring.cpp.

108{
109 if (r < w) {
110 return w - r;
111 } else {
112 return (w - r + ring->size) & ring->size_mask;
113 }
114}
uint32_t size_mask
Mask for fast modulo.
Definition: ring.cpp:55

References ZixRingImpl::size, and ZixRingImpl::size_mask.

Referenced by peek_internal(), zix_ring_read_space(), and zix_ring_skip().

Here is the caller graph for this function:

◆ write_space_internal()

static uint32_t write_space_internal ( const ZixRing ring,
uint32_t  r,
uint32_t  w 
)
inlinestatic

Definition at line 123 of file ring.cpp.

124{
125 if (r == w) {
126 return ring->size - 1;
127 } else if (r < w) {
128 return ((r - w + ring->size) & ring->size_mask) - 1;
129 } else {
130 return (r - w) - 1;
131 }
132}

References ZixRingImpl::size, and ZixRingImpl::size_mask.

Referenced by zix_ring_write(), and zix_ring_write_space().

Here is the caller graph for this function: