30#define SPSC_RING_TESTS(X) \
31 X("spsc_ring::make_valid", test_spsc_ring_make_valid), \
32 X("spsc_ring::make_out_of_range", test_spsc_ring_make_oor), \
33 X("spsc_ring::fill_drain_wrap", test_spsc_ring_fill_drain), \
34 X("spsc_ring::elem_bytes", test_spsc_ring_elem_bytes), \
35 X("spsc_ring::spsc_stress", test_spsc_ring_spsc_stress)
86 for (uint64_t i = 0; i < 4; i++) {
90 uint64_t overflow = 99;
98 uint64_t a = 4, b = 5;
102 for (uint64_t expect = 2; expect <= 5; expect++) {
126 spsc_pair in = {.a = 0xDEADBEEFU, .b = 0x12345678U};
131 TEST_CHECK(out.
a == 0xDEADBEEFU && out.
b == 0x12345678U);
144 for (uint64_t i = 0; i < a->
count; i++) {
163 constexpr uint64_t
n = 100000;
168 bool in_order =
true;
169 for (uint64_t i = 0; i <
n; i++) {
static srn_fiber_result_t producer(srn_context_t *ctx, void *arg)
#define TEST_ASSERT(cond)
#define RELEASE_CONTEXT(x)
#define SHUTDOWN_ENGINE(mm, engine)
#define MAKE_ENGINE(mm, engine)
#define MAKE_CONTEXT(engine, x)
#define HAS_ERROR(x)
True when x – a value carrying an ERROR_HEADER – has an error attached.
bool srn_spsc_ring_push(srn_spsc_ring_t *r, const void *elem)
Producer side.
bool srn_spsc_ring_empty(const srn_spsc_ring_t *r)
Whether the ring currently holds no elements.
srn_spsc_ring_t * srn_spsc_ring_make(srn_context_t *ctx, size_t magnitude, size_t elem_size)
Set up a ring by allocating the buf to be the size of cap * elem_size.
bool srn_spsc_ring_pop(srn_spsc_ring_t *r, void *out)
Consumer side.
A mutable single producer, single consumer ring of fixed size elements.
static void test_spsc_ring_make_valid()
static void test_spsc_ring_make_oor()
static void test_spsc_ring_elem_bytes()
static void test_spsc_ring_spsc_stress()
static void test_spsc_ring_fill_drain()
static void spsc_producer(void *p)
SRN_SPSC_RING_CAP_TYPE cap
SRN_SPSC_RING_CAP_TYPE mask
srn_thread_t, srn_mutex_t, and srn_cond_t model the thread-level operations the runtime needs,...
srn_thread_status_t srn_thread_join(srn_thread_t *t)
Block until the thread started for t returns.
srn_thread_status_t srn_thread_spawn(srn_thread_t *t, void(*fn)(void *), void *arg)
Run fn(arg) on a new OS thread.