📨 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
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
26struct mpmc;
27
32#define make_mpmc(N, T) mpmc_alloc((N), sizeof(T))
33
39#define sizeof_mpmc(N, T) mpmc_open(NULL, (N), sizeof(T))
40
43#define mpmc_send1(C, SRC) mpmc_send((C), 1, (SRC))
44
47#define mpmc_nbsend1(C, SRC) mpmc_nbsend((C), 1, (SRC))
48
51#define mpmc_recv1(C, DST) mpmc_recv((C), 1, (DST))
52
55#define mpmc_nbrecv1(C, DST) mpmc_nbrecv((C), 1, (DST))
56
70size_t mpmc_open(void *c, size_t nel, size_t elsize);
71
83struct mpmc *mpmc_alloc(size_t nel, size_t elsize);
84
90bool mpmc_close(struct mpmc *c);
91
96size_t mpmc_nel(struct mpmc *c);
97
123bool mpmc_send_init(struct mpmc *c, size_t n, struct claim *s);
124
153size_t mpmc_send_nbinit(struct mpmc *c, size_t n, struct claim *s);
154
171bool mpmc_send_fini(struct mpmc *c, struct claim *s);
172
190bool mpmc_send_nbfini(struct mpmc *c, struct claim *s);
191
205bool mpmc_send(struct mpmc *restrict c, size_t n, void *restrict src);
206
222size_t mpmc_nbsend(struct mpmc *restrict c, size_t n, void *restrict src);
223
237bool mpmc_sendv(struct mpmc *restrict c, size_t n, ...);
238
254size_t mpmc_nbsendv(struct mpmc *restrict c, size_t n, ...);
255
282bool mpmc_recv_init(struct mpmc *c, size_t n, struct claim *r);
283
308size_t mpmc_recv_nbinit(struct mpmc *c, size_t n, struct claim *r);
309
326bool mpmc_recv_fini(struct mpmc *c, struct claim *r);
327
345bool mpmc_recv_nbfini(struct mpmc *c, struct claim *r);
346
361bool mpmc_recv(struct mpmc *restrict c, size_t n, void *restrict dst);
362
374size_t mpmc_nbrecv(struct mpmc *restrict c, size_t n, void *restrict dst);
375
390bool mpmc_recvv(struct mpmc *restrict c, size_t n, ...);
391
403size_t mpmc_nbrecvv(struct mpmc *restrict c, size_t n, ...);
404
405#ifdef __cplusplus
406 }
407 #undef restrict
408#endif
Exclusive claims for directly reading/writing into channels.
bool 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...
bool 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...
bool 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...
bool 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...
size_t 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.
bool mpmc_send_init(struct mpmc *c, size_t n, struct claim *s)
Claims space in the channel to be manually written into.
bool mpmc_recv_init(struct mpmc *c, size_t n, struct claim *r)
Claims space in the channel to be manually read from.
size_t 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.
size_t mpmc_nbsendv(struct mpmc *restrict c, size_t n,...)
Sends whatever items will fit to a channel.
size_t mpmc_nbrecvv(struct mpmc *restrict c, size_t n,...)
Receives whatever items are available from a channel.
bool mpmc_close(struct mpmc *c)
Closes a channel, forbidding any future send operations on it.
size_t mpmc_nbsend(struct mpmc *restrict c, size_t n, void *restrict src)
Sends whatever items will fit to a channel.
bool mpmc_send(struct mpmc *restrict c, size_t n, void *restrict src)
Sends items to a channel.
bool mpmc_sendv(struct mpmc *restrict c, size_t n,...)
Sends items to a channel.
size_t mpmc_nbrecv(struct mpmc *restrict c, size_t n, void *restrict dst)
Receives whatever items are available from a channel.
bool mpmc_recv(struct mpmc *restrict c, size_t n, void *restrict dst)
Receives items from a channel.
bool mpmc_recvv(struct mpmc *restrict c, size_t n,...)
Receives items from a channel.
struct mpmc * mpmc_alloc(size_t nel, size_t elsize)
Allocates a new mpmc using malloc() and opens it.
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.
Claimed space for reading or writing directly into the internal ringbuffer of a channel.
Definition claim.h:66
Multiple-producer, multiple-consumer channel.