|
Serene Runtime 1.0.0-dev
C runtime for the Serene programming language
|
A mutable single producer, single consumer ring of fixed size elements. More...
#include <stdbool.h>#include <stddef.h>#include <stdint.h>#include <string.h>#include "serene/rt/errors.h"Go to the source code of this file.
Data Structures | |
| struct | srn_spsc_ring_t |
Macros | |
| #define | SRN_SPSC_RING_CAP_TYPE uint32_t |
Typedefs | |
| typedef struct srn_spsc_ring_t | srn_spsc_ring_t |
Functions | |
| 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_push (srn_spsc_ring_t *r, const void *elem) |
| Producer side. | |
| bool | srn_spsc_ring_pop (srn_spsc_ring_t *r, void *out) |
| Consumer side. | |
| bool | srn_spsc_ring_empty (const srn_spsc_ring_t *r) |
| Whether the ring currently holds no elements. | |
A mutable single producer, single consumer ring of fixed size elements.
One side pushes, the other pops, with no lock between them. The producer owns tail and the consumer owns head; both are monotonic counters, so the live slot for an index is index & mask and the capacity is a power of two. The acquire/release pairing makes it correct on weakly ordered processors, not only x86. A push releases the written element through tail, which the consumer reads with acquire; a pop releases the freed slot through head, which the producer reads with acquire.
Definition in file spsc_ring.h.
| #define SRN_SPSC_RING_CAP_TYPE uint32_t |
Definition at line 41 of file spsc_ring.h.
| typedef struct srn_spsc_ring_t srn_spsc_ring_t |
| bool srn_spsc_ring_empty | ( | const srn_spsc_ring_t * | r | ) |
Whether the ring currently holds no elements.
For the consumer this is exact; for any other observer it is a hint.
Definition at line 103 of file spsc_ring.c.
| 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.
And it will choose the cap to be 2 ^ magnitude.
Definition at line 27 of file spsc_ring.c.
| bool srn_spsc_ring_pop | ( | srn_spsc_ring_t * | r, |
| void * | out ) |
Consumer side.
Copy one element into *out. Returns false when the ring is empty, leaving *out untouched.
Definition at line 83 of file spsc_ring.c.
| bool srn_spsc_ring_push | ( | srn_spsc_ring_t * | r, |
| const void * | elem ) |
Producer side.
Copy *elem into the ring. Returns false when the ring is full, leaving it unchanged.
Definition at line 61 of file spsc_ring.c.