35 #ifndef LELY_UTIL_SPSCRING_H_ 36 #define LELY_UTIL_SPSCRING_H_ 48 #if defined(__cplusplus) 49 typedef ::std::atomic_size_t spscring_atomic_t;
50 #elif __STDC_NO_ATOMICS__ 51 typedef size_t spscring_atomic_t;
53 typedef atomic_size_t spscring_atomic_t;
70 -
sizeof(
struct spscring_ctx)];
74 spscring_atomic_t size;
75 void (*func)(
struct spscring *ring,
void *arg);
79 -
sizeof(
struct spscring_sig)];
84 #if !defined(__cplusplus) && __STDC_NO_ATOMICS__ 85 #define SPSCRING_INIT(size) \ 87 { { (size), 0, 0, 0 }, { 0 }, 0, { 0 }, { 0, NULL, NULL }, \ 90 { (size), 0, 0, 0 }, { 0 }, 0, { 0 }, \ 91 { 0, NULL, NULL }, { 0 }, \ 95 #define SPSCRING_INIT(size) \ 98 { (size), 0, 0, 0 }, \ 100 ATOMIC_VAR_INIT(0), \ 102 { ATOMIC_VAR_INIT(0), NULL, NULL }, \ 106 { (size), 0, 0, 0 }, { 0 }, ATOMIC_VAR_INIT(0), { 0 }, \ 107 { ATOMIC_VAR_INIT(0), NULL, NULL }, \ 226 void (*func)(
struct spscring *ring,
void *arg),
void *arg);
344 void (*func)(
struct spscring *ring,
void *arg),
void *arg);
362 #endif // !LELY_UTIL_SPSCRING_H_ size_t spscring_p_capacity(struct spscring *ring)
Returns the total capacity available for a producer in a single-producer single-consumer ring buffer...
int spscring_c_abort_wait(struct spscring *ring)
Aborts a wait operation previously registered with spscring_c_submit_wait().
size_t spscring_p_commit(struct spscring *ring, size_t size)
Makes the specified number of indices available to a consumer and, if this satisfies a wait operation...
size_t spscring_c_capacity_no_wrap(struct spscring *ring)
Returns the total capacity available for a consumer in a single-producer single-consumer ring buffer...
int spscring_c_submit_wait(struct spscring *ring, size_t size, void(*func)(struct spscring *ring, void *arg), void *arg)
Checks if the requested range of indices, including wrapping, in a single-producer, single-consumer ring buffer is available for reading and, if not, registers a signal function to be invoked once the requested range becomes available.
size_t spscring_p_alloc_no_wrap(struct spscring *ring, size_t *psize)
Allocates a consecutive range of indices, without wrapping, in a single-producer, single-consumer rin...
size_t spscring_c_capacity(struct spscring *ring)
Returns the total capacity available for a consumer in a single-producer single-consumer ring buffer...
#define LEVEL1_DCACHE_LINESIZE
The presumed size (in bytes) of a line in the L1 data cache.
This header file is part of the C11 and POSIX compatibility library; it includes <stdatomic.h>, if it exists, and defines any missing functionality.
size_t spscring_p_alloc(struct spscring *ring, size_t *psize)
Allocates a consecutive range of indices, including wrapping, in a single-producer, single-consumer ring buffer for writing.
size_t spscring_c_alloc(struct spscring *ring, size_t *psize)
Allocates a consecutive range of indices, including wrapping, in a single-producer, single-consumer ring buffer for reading.
void spscring_init(struct spscring *ring, size_t size)
Initializes a single-producer, single-consumer ring buffer with the specified size.
size_t spscring_c_alloc_no_wrap(struct spscring *ring, size_t *psize)
Allocates a consecutive range of indices, without wrapping, in a single-producer, single-consumer rin...
This header file is part of the C11 and POSIX compatibility library; it includes <stddef.h> and defines any missing functionality.
int spscring_p_submit_wait(struct spscring *ring, size_t size, void(*func)(struct spscring *ring, void *arg), void *arg)
Checks if the requested range of indices, including wrapping, in a single-producer, single-consumer ring buffer is available for writing and, if not, registers a signal function to be invoked once the requested range becomes available.
size_t spscring_p_capacity_no_wrap(struct spscring *ring)
Returns the total capacity available for a producer in a single-producer single-consumer ring buffer...
A single-producer, single-consumer ring buffer.
int spscring_p_abort_wait(struct spscring *ring)
Aborts a wait operation previously registered with spscring_p_submit_wait().
This header file is part of the Lely libraries; it contains the compiler feature definitions.
size_t spscring_c_commit(struct spscring *ring, size_t size)
Makes the specified number of indices available to a producer and, if this satisfies a wait operation...
size_t spscring_size(const struct spscring *ring)
Returns the size of a single-producer, single-consumer ring buffer.