📨 chic 0.0.0
Realtime-safe channels in C
Loading...
Searching...
No Matches
spmc.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 spmc;
28
33#define make_spmc(N, T) spmc_alloc((N), sizeof(T))
34
40#define sizeof_spmc(N, T) spmc_open(NULL, (N), sizeof(T))
41
44#define spmc_send1(C, SRC) spmc_send((C), 1, (SRC))
45
48#define spmc_nbsend1(C, SRC) spmc_nbsend((C), 1, (SRC))
49
52#define spmc_recv1(C, DST) spmc_recv((C), 1, (DST))
53
56#define spmc_nbrecv1(C, DST) spmc_nbrecv((C), 1, (DST))
57
71size_t spmc_open(void *c, size_t nel, size_t elsize);
72
84struct spmc *spmc_alloc(size_t nel, size_t elsize);
85
93bool spmc_close(struct spmc *c);
94
99size_t spmc_nel(struct spmc *c);
100
126bool spmc_send_init(struct spmc *c, size_t n, struct claim *s);
127
156size_t spmc_send_nbinit(struct spmc *c, size_t n, struct claim *s);
157
168bool spmc_send_fini(struct spmc *c, struct claim *s);
169
183bool spmc_send(struct spmc *restrict c, size_t n, void *restrict src);
184
200size_t spmc_nbsend(struct spmc *restrict c, size_t n, void *restrict src);
201
215bool spmc_sendv(struct spmc *restrict c, size_t n, ...);
216
232size_t spmc_nbsendv(struct spmc *restrict c, size_t n, ...);
233
260bool spmc_recv_init(struct spmc *c, size_t n, struct claim *r);
261
286size_t spmc_recv_nbinit(struct spmc *c, size_t n, struct claim *r);
287
304bool spmc_recv_fini(struct spmc *c, struct claim *r);
305
323bool spmc_recv_nbfini(struct spmc *c, struct claim *r);
324
339bool spmc_recv(struct spmc *restrict c, size_t n, void *restrict dst);
340
352size_t spmc_nbrecv(struct spmc *restrict c, size_t n, void *restrict dst);
353
368bool spmc_recvv(struct spmc *restrict c, size_t n, ...);
369
381size_t spmc_nbrecvv(struct spmc *restrict c, size_t n, ...);
382
383#ifdef __cplusplus
384 }
385 #undef restrict
386#endif
Exclusive claims for directly reading/writing into channels.
size_t spmc_send_nbinit(struct spmc *c, size_t n, struct claim *s)
Claims up to an amount of space in the channel to be manually written into.
size_t spmc_recv_nbinit(struct spmc *c, size_t n, struct claim *r)
Claims up to an amount of space in the channel to be manually read from.
bool spmc_recv_init(struct spmc *c, size_t n, struct claim *r)
Claims space in the channel to be manually read from.
bool spmc_send_fini(struct spmc *c, struct claim *s)
Commits a claim, indicating the item slots within have been written to and are ready to be received.
bool spmc_recv_nbfini(struct spmc *c, struct claim *r)
Tries to commit a claim, indicating the item slots within have been read from and are safe to be over...
bool spmc_recv_fini(struct spmc *c, struct claim *r)
Commits a claim, indicating the item slots within have been read from and are ready to be overwritten...
bool spmc_send_init(struct spmc *c, size_t n, struct claim *s)
Claims space in the channel to be manually written into.
bool spmc_recv(struct spmc *restrict c, size_t n, void *restrict dst)
Receives items from a channel.
size_t spmc_nel(struct spmc *c)
Gets the maximim number of elements a channel is capable of holding at once.
bool spmc_close(struct spmc *c)
Closes a channel, forbidding any future send operations on it.
size_t spmc_open(void *c, size_t nel, size_t elsize)
Constructs a spmc in-place, or calculates the needed allocation size for one.
size_t spmc_nbsend(struct spmc *restrict c, size_t n, void *restrict src)
Sends whatever items will fit to a channel.
size_t spmc_nbsendv(struct spmc *restrict c, size_t n,...)
Sends whatever items will fit to a channel.
bool spmc_send(struct spmc *restrict c, size_t n, void *restrict src)
Sends items to a channel.
bool spmc_sendv(struct spmc *restrict c, size_t n,...)
Sends items to a channel.
size_t spmc_nbrecv(struct spmc *restrict c, size_t n, void *restrict dst)
Receives whatever items are available from a channel.
bool spmc_recvv(struct spmc *restrict c, size_t n,...)
Receives items from a channel.
size_t spmc_nbrecvv(struct spmc *restrict c, size_t n,...)
Receives whatever items are available from a channel.
struct spmc * spmc_alloc(size_t nel, size_t elsize)
Allocates a new spmc using malloc() and opens it.
Claimed space for reading or writing directly into the internal ringbuffer of a channel.
Definition claim.h:66
Single-producer, multiple-consumer channel.