3#ifndef PROTOCORE_RING_H
4#define PROTOCORE_RING_H
55 v.store(o.v.load(std::memory_order_acquire), std::memory_order_release);
60 v.store(x, std::memory_order_release);
65 operator T() const noexcept
67 return v.load(std::memory_order_acquire);
83 return ((
size_t)head + cap - (
size_t)tail) % cap;
87static inline bool pc_ring_read_byte(
const uint8_t *buf,
size_t cap,
const pc_atomic<size_t> &head,
91 if (t == (
size_t)head)
101static inline size_t pc_ring_read(
const uint8_t *buf,
size_t cap,
const pc_atomic<size_t> &head,
107 while (n < maxn && t != h)
117static inline void pc_ring_peek(
const uint8_t *buf,
size_t cap,
const pc_atomic<size_t> &tail,
size_t off, uint8_t *dst,
120 size_t idx = ((size_t)tail + off) % cap;
121 for (
size_t i = 0; i < n; i++)
124 idx = (idx + 1) % cap;
131 tail = ((size_t)tail + n) % cap;
145 size_t used = ((size_t)head + cap - (
size_t)tail) % cap;
146 return (cap - 1) - used;
155static inline size_t pc_ring_write_span(uint8_t *buf,
size_t cap,
size_t head,
const uint8_t *src,
size_t len)
159 size_t chunk = cap - head;
164 memcpy(&buf[head], src, chunk);
165 head = (head + chunk) % cap;
pc_atomic & operator=(const pc_atomic &o) noexcept
pc_atomic(const pc_atomic &o) noexcept
pc_atomic & operator=(T x) noexcept