📨 chic 0.0.0
Realtime-safe channels in C
Loading...
Searching...
No Matches
mpsc.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 mpsc;
28
33#define make_mpsc(N, T) mpsc_alloc((N), sizeof(T))
34
40#define sizeof_mpsc(N, T) mpsc_open(NULL, (N), sizeof(T))
41
44#define mpsc_send1(C, SRC) mpsc_send((C), 1, (SRC))
45
48#define mpsc_nbsend1(C, SRC) mpsc_nbsend((C), 1, (SRC))
49
52#define mpsc_recv1(C, DST) mpsc_recv((C), 1, (DST))
53
56#define mpsc_nbrecv1(C, DST) mpsc_nbrecv((C), 1, (DST))
57
71size_t mpsc_open(void *c, size_t nel, size_t elsize);
72
84struct mpsc *mpsc_alloc(size_t nel, size_t elsize);
85
91bool mpsc_close(struct mpsc *c);
92
97size_t mpsc_nel(struct mpsc *c);
98
124bool mpsc_send_init(struct mpsc *c, size_t n, struct claim *s);
125
154size_t mpsc_send_nbinit(struct mpsc *c, size_t n, struct claim *s);
155
172bool mpsc_send_fini(struct mpsc *c, struct claim *s);
173
191bool mpsc_send_nbfini(struct mpsc *c, struct claim *s);
192
206bool mpsc_send(struct mpsc *restrict c, size_t n, void *restrict src);
207
223size_t mpsc_nbsend(struct mpsc *restrict c, size_t n, void *restrict src);
224
238bool mpsc_sendv(struct mpsc *restrict c, size_t n, ...);
239
255size_t mpsc_nbsendv(struct mpsc *restrict c, size_t n, ...);
256
283bool mpsc_recv_init(struct mpsc *c, size_t n, struct claim *r);
284
309size_t mpsc_recv_nbinit(struct mpsc *c, size_t n, struct claim *r);
310
321bool mpsc_recv_fini(struct mpsc *c, struct claim *r);
322
337bool mpsc_recv(struct mpsc *restrict c, size_t n, void *restrict dst);
338
350size_t mpsc_nbrecv(struct mpsc *restrict c, size_t n, void *restrict dst);
351
366bool mpsc_recvv(struct mpsc *restrict c, size_t n, ...);
367
379size_t mpsc_nbrecvv(struct mpsc *restrict c, size_t n, ...);
380
381#ifdef __cplusplus
382 }
383 #undef restrict
384#endif
Exclusive claims for directly reading/writing into channels.
bool mpsc_recv_fini(struct mpsc *c, struct claim *r)
Commits a claim, indicating the item slots within have been read from and are safe to be overwritten.
size_t mpsc_recv_nbinit(struct mpsc *c, size_t n, struct claim *r)
Claims up to an amount of space in the channel to be manually read from.
bool mpsc_send_init(struct mpsc *c, size_t n, struct claim *s)
Claims space in the channel to be manually written into.
size_t mpsc_send_nbinit(struct mpsc *c, size_t n, struct claim *s)
Claims up to an amount of space in the channel to be manually written into.
bool mpsc_send_fini(struct mpsc *c, struct claim *s)
Commits a claim, indicating the item slots within are finished being written to and are ready to be r...
bool mpsc_send_nbfini(struct mpsc *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 mpsc_recv_init(struct mpsc *c, size_t n, struct claim *r)
Claims space in the channel to be manually read from.
bool mpsc_sendv(struct mpsc *restrict c, size_t n,...)
Sends items to a channel.
struct mpsc * mpsc_alloc(size_t nel, size_t elsize)
Allocates a new mpsc using malloc() and opens it.
size_t mpsc_nbrecvv(struct mpsc *restrict c, size_t n,...)
Receives whatever items are available from a channel.
size_t mpsc_nbsendv(struct mpsc *restrict c, size_t n,...)
Sends whatever items will fit to a channel.
size_t mpsc_nel(struct mpsc *c)
Gets the maximim number of elements a channel is capable of holding at once.
size_t mpsc_nbrecv(struct mpsc *restrict c, size_t n, void *restrict dst)
Receives whatever items are available from a channel.
size_t mpsc_nbsend(struct mpsc *restrict c, size_t n, void *restrict src)
Sends whatever items will fit to a channel.
bool mpsc_send(struct mpsc *restrict c, size_t n, void *restrict src)
Sends items to a channel.
bool mpsc_recvv(struct mpsc *restrict c, size_t n,...)
Receives items from a channel.
bool mpsc_recv(struct mpsc *restrict c, size_t n, void *restrict dst)
Receives items from a channel.
bool mpsc_close(struct mpsc *c)
Closes a channel, forbidding any future send operations on it.
size_t mpsc_open(void *c, size_t nel, size_t elsize)
Constructs a mpsc 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
Multiple-producer, single-consumer channel.