|
📨 chic 0.0.0
Realtime-safe channels in C
|
Single-producer, single-consumer channel. More...
#include "claim.h"Go to the source code of this file.
Macros | |
| #define | make_spsc(N, T) |
| Convenience macro for allocating a new spsc. | |
| #define | sizeof_spsc(N, T) |
| Convenience macro for calculating the size of a spsc with certain parameters. | |
| #define | spsc_send1(C, SRC) |
| Convenience macro for sending a single item to a channel. | |
| #define | spsc_nbsend1(C, SRC) |
| Convenience macro for sending a single item to a channel. | |
| #define | spsc_recv1(C, DST) |
| Convenience macro for receiving a single item from a channel. | |
| #define | spsc_nbrecv1(C, DST) |
| Convenience macro for receiving a single item from a channel. | |
Functions | |
| size_t | spsc_open (void *c, size_t nel, size_t elsize) |
| Constructs a spsc in-place, or calculates the needed allocation size for one. | |
| struct spsc * | spsc_alloc (size_t nel, size_t elsize) |
| Allocates a new spsc using malloc() and opens it. | |
| bool | spsc_close (struct spsc *c) |
| Closes a channel, forbidding any future send operations on it. | |
| size_t | spsc_nel (struct spsc *c) |
| Gets the maximim number of elements a channel is capable of holding at once. | |
| bool | spsc_send_init (struct spsc *c, size_t n, struct claim *s) |
| Claims space in the channel to be manually written into. | |
| size_t | spsc_send_nbinit (struct spsc *c, size_t n, struct claim *s) |
| Claims up to an amount of space in the channel to be manually written into. | |
| bool | spsc_send_fini (struct spsc *c, struct claim *s) |
| Tries to commit a claim, indicating the item slots within have been written to and are ready to be received. | |
| bool | spsc_send (struct spsc *restrict c, size_t n, void *restrict src) |
| Sends items to a channel. | |
| size_t | spsc_nbsend (struct spsc *restrict c, size_t n, void *restrict src) |
| Sends whatever items will fit to a channel. | |
| bool | spsc_sendv (struct spsc *restrict c, size_t n,...) |
| Sends items to a channel. | |
| size_t | spsc_nbsendv (struct spsc *restrict c, size_t n,...) |
| Sends whatever items will fit to a channel. | |
| bool | spsc_recv_init (struct spsc *c, size_t n, struct claim *r) |
| Claims space in the channel to be manually read from. | |
| size_t | spsc_recv_nbinit (struct spsc *c, size_t n, struct claim *r) |
| Claims up to an amount of space in the channel to be manually read from. | |
| bool | spsc_recv_fini (struct spsc *c, struct claim *r) |
| Commits a claim, indicating the item slots within have been read from and are safe to be overwritten. | |
| bool | spsc_recv (struct spsc *restrict c, size_t n, void *restrict dst) |
| Receives items from a channel. | |
| size_t | spsc_nbrecv (struct spsc *restrict c, size_t n, void *restrict dst) |
| Receives whatever items are available from a channel. | |
| bool | spsc_recvv (struct spsc *restrict c, size_t n,...) |
| Receives items from a channel. | |
| size_t | spsc_nbrecvv (struct spsc *restrict c, size_t n,...) |
| Receives whatever items are available from a channel. | |
Single-producer, single-consumer channel.
| #define make_spsc | ( | N, | |
| T ) |
Convenience macro for allocating a new spsc.
| N | The capacity of the channel; must be a nonzero power of 2 |
| T | The type of a channel element |
| #define sizeof_spsc | ( | N, | |
| T ) |
Convenience macro for calculating the size of a spsc with certain parameters.
| N | The capacity of the channel; must be a nonzero power of 2 |
| T | The type of a channel element |
| #define spsc_nbrecv1 | ( | C, | |
| DST ) |
Convenience macro for receiving a single item from a channel.
| #define spsc_nbsend1 | ( | C, | |
| SRC ) |
Convenience macro for sending a single item to a channel.
| #define spsc_recv1 | ( | C, | |
| DST ) |
| #define spsc_send1 | ( | C, | |
| SRC ) |
| struct spsc * spsc_alloc | ( | size_t | nel, |
| size_t | elsize ) |
Allocates a new spsc using malloc() and opens it.
| nel | The minimum number of elements the channel should be able to hold; must be a nonzero power of 2 |
| elsize | The sizeof the type of a channel element |
| EINVAL | if nel is 0, or if elsize is 0 or not a power of 2 |
| ENOMEM | if out of memory |
| bool spsc_close | ( | struct spsc * | c | ) |
Closes a channel, forbidding any future send operations on it.
| c | The channel to close; must be non-nil |
| EBUSY | if chan has unreceived items |
| size_t spsc_nbrecv | ( | struct spsc *restrict | c, |
| size_t | n, | ||
| void *restrict | dst ) |
Receives whatever items are available from a channel.
| c | The channel to receive items from; must be non-nil |
| n | The number of items to receive |
| dst | Where to receive the items into |
| EINVAL | if n is not within the range [0, nel], where nel is the capacity of c, or if dst is nil |
| ENOMSG | if there is nothing to receive from the channel |
| EPIPE | if chan is closed and there are no more items to receive |
| size_t spsc_nbrecvv | ( | struct spsc *restrict | c, |
| size_t | n, | ||
| ... ) |
Receives whatever items are available from a channel.
| c | The channel to receive items from; must be non-nil |
| n | The number of items to receive |
| ... | Where to receive the items into |
| EINVAL | if n is not within the range [0, nel], where nel is the capacity of c |
| ENOMSG | if there is nothing to receive from the channel |
| EPIPE | if chan is closed and there are no more items to receive |
| size_t spsc_nbsend | ( | struct spsc *restrict | c, |
| size_t | n, | ||
| void *restrict | src ) |
Sends whatever items will fit to a channel.
If the channel has less than n available item slots for writing, this function will send whatever items will fit. If there is no space available, this function will return 0.
| c | The channel to try to send items to; must be non-nil |
| n | The maximum number of items to try to send |
| src | Where to send the items from |
| EINVAL | if n is not within the range [0, nel], where nel is the capacity of c, or if src is nil |
| ENOBUFS | if there is no room in the channel |
| EPIPE | if chan is closed and can no longer be sent to |
| size_t spsc_nbsendv | ( | struct spsc *restrict | c, |
| size_t | n, | ||
| ... ) |
Sends whatever items will fit to a channel.
If the channel has less than n available item slots for writing, this function will send whatever items will fit. If there is no space available, this function will return 0.
| c | The channel to try to send items to; must be non-nil |
| n | The maximum number of items to try to send |
| ... | Pointers to the items to send |
| EINVAL | if n is not within the range [0, nel], where nel is the capacity of c |
| ENOBUFS | if there is no room in the channel |
| EPIPE | if chan is closed and can no longer be sent to |
| size_t spsc_nel | ( | struct spsc * | c | ) |
Gets the maximim number of elements a channel is capable of holding at once.
| c | The channel to get the capacity of; must be non-nil |
c | size_t spsc_open | ( | void * | c, |
| size_t | nel, | ||
| size_t | elsize ) |
Constructs a spsc in-place, or calculates the needed allocation size for one.
| [out] | c | The address at which to construct a spsc; may be nil |
| [in] | nel | The number of elements the channel can hold; must be a nonzero power of 2 |
| [in] | elsize | The sizeof the type of an element |
c was not nil, the size of the constructed spsc). If there was an error, returns 0. If 0 is returned, errno is set to indicate the reason why. | EINVAL | if nel is 0, or if elsize is 0 or not a power of 2 |
| bool spsc_recv | ( | struct spsc *restrict | c, |
| size_t | n, | ||
| void *restrict | dst ) |
Receives items from a channel.
If the channel does not have n or more available items ready to be received, this function will busy-wait until there are.
| c | The channel to receive items from; must be non-nil |
| n | The number of items to receive |
| dst | Where to receive the items into |
| EINVAL | if n is not within the range [0, nel], where nel is the capacity of c, or if dst is nil |
| EPIPE | if chan is closed and there are less than n items remaining to receive |
| bool spsc_recvv | ( | struct spsc *restrict | c, |
| size_t | n, | ||
| ... ) |
Receives items from a channel.
If the channel does not have n or more available items ready to be received, this function will busy-wait until there are.
| c | The channel to receive items from; must be non-nil |
| n | The number of items to receive |
| ... | Where to receive the items into |
| EINVAL | if n is not within the range [0, nel], where nel is the capacity of c |
| EPIPE | if chan is closed and there are less than n items remaining to receive |
| bool spsc_send | ( | struct spsc *restrict | c, |
| size_t | n, | ||
| void *restrict | src ) |
Sends items to a channel.
If the channel does not have enough free space to send all n items, this function will busy-wait until there are.
| c | The channel to send items to; must be non-nil |
| n | The number of items to send; must be non-nil |
| src | Where to send the items from |
| EINVAL | if n is not within the range [0, nel], where nel is the capacity of c, or if src is nil |
| EPIPE | if chan is closed and can no longer be sent to |
| bool spsc_sendv | ( | struct spsc *restrict | c, |
| size_t | n, | ||
| ... ) |
Sends items to a channel.
If the channel does not have enough free space to send all n items, this function will busy-wait until there are.
| c | The channel to send items to; must be non-nil |
| n | The number of items to send |
| ... | Pointers to the items to send |
| EINVAL | if n is not within the range [0, nel], where nel is the capacity of c |
| EPIPE | if chan is closed and can no longer be sent to |