23# define ZIX_MLOCK(ptr, size) mlock((ptr), (size))
26# define ZIX_MLOCK(ptr, size) VirtualLock((ptr), (size))
28# pragma message("warning: No memory locking, possible RT violations")
29# define ZIX_MLOCK(ptr, size)
33# include <libkern/OSAtomic.h>
34# define ZIX_FULL_BARRIER() OSMemoryBarrier()
37# define ZIX_FULL_BARRIER() MemoryBarrier()
38#elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
39# define ZIX_FULL_BARRIER() __sync_synchronize()
41# pragma message("warning: No memory barriers, possible SMP bugs")
42# define ZIX_FULL_BARRIER()
46#define ZIX_READ_BARRIER() ZIX_FULL_BARRIER()
47#define ZIX_WRITE_BARRIER() ZIX_FULL_BARRIER()
81 ring->
buf = (
char*)malloc(ring->
size);
106static inline uint32_t
122static inline uint32_t
126 return ring->
size - 1;
143 return ring->
size - 1;
146static inline uint32_t
148 uint32_t
size,
void* dst)
154 if (r + size < ring->
size) {
155 memcpy(dst, &ring->
buf[r],
size);
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);
209 if (w + size <= ring->
size) {
210 memcpy(&ring->
buf[w], src,
size);
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);
void zix_ring_reset(ZixRing *ring)
uint32_t zix_ring_read(ZixRing *ring, void *dst, uint32_t size)
void zix_ring_free(ZixRing *ring)
ZixRing * zix_ring_new(uint32_t size)
uint32_t zix_ring_read_space(const ZixRing *ring)
uint32_t zix_ring_capacity(const ZixRing *ring)
uint32_t zix_ring_write_space(const ZixRing *ring)
uint32_t zix_ring_peek(ZixRing *ring, void *dst, uint32_t size)
uint32_t zix_ring_write(ZixRing *ring, const void *src, uint32_t size)
uint32_t zix_ring_skip(ZixRing *ring, uint32_t size)
void zix_ring_mlock(ZixRing *ring)
static uint32_t read_space_internal(const ZixRing *ring, uint32_t r, uint32_t w)
#define ZIX_WRITE_BARRIER()
#define ZIX_READ_BARRIER()
#define ZIX_MLOCK(ptr, size)
static uint32_t next_power_of_two(uint32_t size)
static uint32_t peek_internal(const ZixRing *ring, uint32_t r, uint32_t w, uint32_t size, void *dst)
static uint32_t write_space_internal(const ZixRing *ring, uint32_t r, uint32_t w)
uint32_t read_head
Write index into buf.
uint32_t size_mask
Mask for fast modulo.
uint32_t size
Size (capacity) in bytes.
uint32_t write_head
Read index into buf.