📨 chic 0.0.0
Realtime-safe channels in C
Loading...
Searching...
No Matches
mpmc.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#include "err.h"
13
14#ifdef __cplusplus
15 #if defined(__clang__) || defined(__GNUG__) || defined(_MSC_VER)
16 #define restrict __restrict
17 #else
18 #define restrict
19 #endif
20 extern "C" {
21#endif
22
27struct mpmc;
28
33#define make_mpmc(N, T) mpmc_alloc((N), sizeof(T))
34
40#define sizeof_mpmc(N, T) mpmc_open(NULL, (N), sizeof(T))
41
44#define mpmc_send1(C, SRC) mpmc_send((C), 1, (SRC))
45
48#define mpmc_nbsend1(C, SRC) mpmc_nbsend((C), 1, NULL, (SRC))
49
52#define mpmc_recv1(C, DST) mpmc_recv((C), 1, (DST))
53
56#define mpmc_nbrecv1(C, DST) mpmc_nbrecv((C), 1, NULL, (DST))
57
69size_t mpmc_open(void *c, size_t nel, size_t elsize);
70
80struct mpmc *mpmc_alloc(size_t nel, size_t elsize);
81
86enum chic_err mpmc_close(struct mpmc *c);
87
92size_t mpmc_nel(struct mpmc *c);
93
117enum chic_err mpmc_send_init(struct mpmc *c, size_t n, struct claim *s);
118
145enum chic_err mpmc_send_nbinit(struct mpmc *c, size_t n, struct claim *s);
146
162void mpmc_send_fini(struct mpmc *c, struct claim *s);
163
181enum chic_err mpmc_send_nbfini(struct mpmc *c, struct claim *s);
182
196enum chic_err mpmc_send(struct mpmc *restrict c, size_t n, void *restrict src);
197
215enum chic_err mpmc_nbsend(struct mpmc *restrict c, size_t n, size_t *restrict n2, void *restrict src);
216
230enum chic_err mpmc_sendv(struct mpmc *restrict c, size_t n, ...);
231
249enum chic_err mpmc_nbsendv(struct mpmc *restrict c, size_t n, size_t *restrict n2, ...);
250
274enum chic_err mpmc_recv_init(struct mpmc *c, size_t n, struct claim *r);
275
298enum chic_err mpmc_recv_nbinit(struct mpmc *c, size_t n, struct claim *r);
299
315void mpmc_recv_fini(struct mpmc *c, struct claim *r);
316
334enum chic_err mpmc_recv_nbfini(struct mpmc *c, struct claim *r);
335
349enum chic_err mpmc_recv(struct mpmc *restrict c, size_t n, void *restrict dst);
350
365enum chic_err mpmc_nbrecv(struct mpmc *restrict c, size_t n, size_t *restrict n2, void *restrict dst);
366
380enum chic_err mpmc_recvv(struct mpmc *restrict c, size_t n, ...);
381
396enum chic_err mpmc_nbrecvv(struct mpmc *restrict c, size_t n, size_t *restrict n2, ...);
397
398#ifdef __cplusplus
399 }
400 #undef restrict
401#endif
Exclusive claims for directly reading/writing into channels.
Error enumeration definition.
chic_err
Identifiers for channel states and errors.
Definition err.h:14
void mpmc_recv_fini(struct mpmc *c, struct claim *r)
Commits a claim, indicating the item slots within have been read from and are ready to be overwritten...
enum chic_err mpmc_recv_nbfini(struct mpmc *c, struct claim *r)
Tries to commit a claim, indicating the item slots within have been read from and are safe to be over...
void mpmc_send_fini(struct mpmc *c, struct claim *s)
Commits a claim, indicating the item slots within are finished being written to and are ready to be r...
enum chic_err mpmc_recv_nbinit(struct mpmc *c, size_t n, struct claim *r)
Claims up to an amount of space in the channel to be manually read from.
enum chic_err mpmc_send_nbinit(struct mpmc *c, size_t n, struct claim *s)
Claims up to an amount of space in the channel to be manually written into.
enum chic_err mpmc_recv_init(struct mpmc *c, size_t n, struct claim *r)
Claims space in the channel to be manually read from.
enum chic_err mpmc_send_nbfini(struct mpmc *c, struct claim *s)
Tries to commit a claim, indicating the item slots within have been written to and are ready to be re...
enum chic_err mpmc_send_init(struct mpmc *c, size_t n, struct claim *s)
Claims space in the channel to be manually written into.
enum chic_err mpmc_recvv(struct mpmc *restrict c, size_t n,...)
Receives items from a channel.
enum chic_err mpmc_send(struct mpmc *restrict c, size_t n, void *restrict src)
Sends items to a channel.
enum chic_err mpmc_nbrecv(struct mpmc *restrict c, size_t n, size_t *restrict n2, void *restrict dst)
Receives whatever items are available from a channel.
enum chic_err mpmc_nbrecvv(struct mpmc *restrict c, size_t n, size_t *restrict n2,...)
Receives whatever items are available from a channel.
enum chic_err mpmc_close(struct mpmc *c)
Closes a channel, forbidding any future send operations on it.
enum chic_err mpmc_recv(struct mpmc *restrict c, size_t n, void *restrict dst)
Receives items from a channel.
enum chic_err mpmc_sendv(struct mpmc *restrict c, size_t n,...)
Sends items to a channel.
struct mpmc * mpmc_alloc(size_t nel, size_t elsize)
Allocates a new mpmc using malloc() and opens it.
enum chic_err mpmc_nbsendv(struct mpmc *restrict c, size_t n, size_t *restrict n2,...)
Sends whatever items will fit to a channel.
size_t mpmc_open(void *c, size_t nel, size_t elsize)
Constructs a mpmc in-place, or calculates the needed allocation size for one.
size_t mpmc_nel(struct mpmc *c)
Gets the maximim number of elements a channel is capable of holding at once.
enum chic_err mpmc_nbsend(struct mpmc *restrict c, size_t n, size_t *restrict n2, void *restrict src)
Sends whatever items will fit to a channel.
Claimed space for reading or writing directly into the internal ringbuffer of a channel.
Definition claim.h:66
Multiple-producer, multiple-consumer channel.