📨 chic 0.0.0
Realtime-safe channels in C
Loading...
Searching...
No Matches
spsc.h
Go to the documentation of this file.
1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
9
10#pragma once
11#include "claim.h"
12
13#ifdef __cplusplus
14 #if defined(__clang__) || defined(__GNUG__) || defined(_MSC_VER)
15 #define restrict __restrict
16 #else
17 #define restrict
18 #endif
19 extern "C" {
20#endif
21
27struct spsc;
28
33#define make_spsc(N, T) spsc_alloc((N), sizeof(T))
34
40#define sizeof_spsc(N, T) spsc_open(NULL, (N), sizeof(T))
41
44#define spsc_send1(C, SRC) spsc_send((C), 1, (SRC))
45
48#define spsc_nbsend1(C, SRC) spsc_nbsend((C), 1, (SRC))
49
52#define spsc_recv1(C, DST) spsc_recv((C), 1, (DST))
53
56#define spsc_nbrecv1(C, DST) spsc_nbrecv((C), 1, (DST))
57
71size_t spsc_open(void *c, size_t nel, size_t elsize);
72
84struct spsc *spsc_alloc(size_t nel, size_t elsize);
85
93bool spsc_close(struct spsc *c);
94
99size_t spsc_nel(struct spsc *c);
100
126bool spsc_send_init(struct spsc *c, size_t n, struct claim *s);
127
156size_t spsc_send_nbinit(struct spsc *c, size_t n, struct claim *s);
157
174bool spsc_send_fini(struct spsc *c, struct claim *s);
175
189bool spsc_send(struct spsc *restrict c, size_t n, void *restrict src);
190
206size_t spsc_nbsend(struct spsc *restrict c, size_t n, void *restrict src);
207
221bool spsc_sendv(struct spsc *restrict c, size_t n, ...);
222
238size_t spsc_nbsendv(struct spsc *restrict c, size_t n, ...);
239
266bool spsc_recv_init(struct spsc *c, size_t n, struct claim *r);
267
292size_t spsc_recv_nbinit(struct spsc *c, size_t n, struct claim *r);
293
304bool spsc_recv_fini(struct spsc *c, struct claim *r);
305
320bool spsc_recv(struct spsc *restrict c, size_t n, void *restrict dst);
321
333size_t spsc_nbrecv(struct spsc *restrict c, size_t n, void *restrict dst);
334
349bool spsc_recvv(struct spsc *restrict c, size_t n, ...);
350
362size_t spsc_nbrecvv(struct spsc *restrict c, size_t n, ...);
363
364#ifdef __cplusplus
365 }
366 #undef restrict
367#endif
Exclusive claims for directly reading/writing into channels.
bool spsc_send_init(struct spsc *c, size_t n, struct claim *s)
Claims space in the channel to be manually written into.
bool spsc_recv_fini(struct spsc *c, struct claim *r)
Commits a claim, indicating the item slots within have been read from and are safe to be overwritten.
bool spsc_send_fini(struct spsc *c, struct claim *s)
Tries to commit a claim, indicating the item slots within have been written to and are ready to be re...
size_t spsc_recv_nbinit(struct spsc *c, size_t n, struct claim *r)
Claims up to an amount of space in the channel to be manually read from.
bool spsc_recv_init(struct spsc *c, size_t n, struct claim *r)
Claims space in the channel to be manually read from.
size_t spsc_send_nbinit(struct spsc *c, size_t n, struct claim *s)
Claims up to an amount of space in the channel to be manually written into.
size_t spsc_nbsendv(struct spsc *restrict c, size_t n,...)
Sends whatever items will fit to a channel.
bool spsc_close(struct spsc *c)
Closes a channel, forbidding any future send operations on it.
bool spsc_recvv(struct spsc *restrict c, size_t n,...)
Receives items from a channel.
bool spsc_recv(struct spsc *restrict c, size_t n, void *restrict dst)
Receives items from a channel.
bool spsc_send(struct spsc *restrict c, size_t n, void *restrict src)
Sends items to a channel.
size_t spsc_nel(struct spsc *c)
Gets the maximim number of elements a channel is capable of holding at once.
size_t spsc_nbrecvv(struct spsc *restrict c, size_t n,...)
Receives whatever items are available from a channel.
struct spsc * spsc_alloc(size_t nel, size_t elsize)
Allocates a new spsc using malloc() and opens it.
size_t spsc_nbrecv(struct spsc *restrict c, size_t n, void *restrict dst)
Receives whatever items are available from a channel.
bool spsc_sendv(struct spsc *restrict c, size_t n,...)
Sends items to a channel.
size_t spsc_nbsend(struct spsc *restrict c, size_t n, void *restrict src)
Sends whatever items will fit to a channel.
size_t spsc_open(void *c, size_t nel, size_t elsize)
Constructs a spsc in-place, or calculates the needed allocation size for one.
Claimed space for reading or writing directly into the internal ringbuffer of a channel.
Definition claim.h:66
Single-producer, single-consumer channel.