📨 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
91bool mpmc_close(struct mpmc *c);
92
109bool mpmc_send_init(struct mpmc *c, size_t n, struct claim *s);
110
130size_t mpmc_nbsend_init(struct mpmc *c, size_t n, struct claim *s);
131
146bool mpmc_send_fini(struct mpmc *c, struct claim *s);
147
171bool mpmc_nbsend_fini(struct mpmc *c, struct claim *s);
172
186bool mpmc_send(struct mpmc *restrict c, size_t n, void *restrict src);
187
203size_t mpmc_nbsend(struct mpmc *restrict c, size_t n, void *restrict src);
204
218bool mpmc_sendv(struct mpmc *restrict c, size_t n, ...);
219
235size_t mpmc_nbsendv(struct mpmc *restrict c, size_t n, ...);
236
254bool mpmc_recv_init(struct mpmc *c, size_t n, struct claim *r);
255
271size_t mpmc_nbrecv_init(struct mpmc *c, size_t n, struct claim *r);
272
287bool mpmc_recv_fini(struct mpmc *c, struct claim *r);
288
312bool mpmc_nbrecv_fini(struct mpmc *c, struct claim *r);
313
328bool mpmc_recv(struct mpmc *restrict c, size_t n, void *restrict dst);
329
341size_t mpmc_nbrecv(struct mpmc *restrict c, size_t n, void *restrict dst);
342
357bool mpmc_recvv(struct mpmc *restrict c, size_t n, ...);
358
370size_t mpmc_nbrecvv(struct mpmc *restrict c, size_t n, ...);
371
372#ifdef __cplusplus
373 }
374 #undef restrict
375#endif
Exclusive claims for directly reading/writing into channels.
size_t mpmc_nbrecv_init(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.
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...
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.
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_nbsend(struct mpmc *restrict c, size_t n, void *restrict src)
Sends whatever items will fit to a channel.
bool mpmc_nbsend_fini(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(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.
size_t mpmc_nbsend_init(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_recvv(struct mpmc *restrict c, size_t n,...)
Receives items from a channel.
bool mpmc_nbrecv_fini(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_send_init(struct mpmc *c, size_t n, struct claim *s)
Claims space in the channel to be manually written into.
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.
bool mpmc_recv_init(struct mpmc *c, size_t n, struct claim *r)
Claims space in the channel to be manually read from.
Claimed space for reading or writing directly into the internal ringbuffer of a channel.
Definition claim.h:26
Multiple-producer, multiple-consumer channel.