|
📨 chic 0.0.0
Realtime-safe channels in C
|
Claimed space for reading or writing directly into the internal ringbuffer of a channel. More...
#include <claim.h>
Data Fields | |
| size_t | seq |
| The sequence number of this claim. | |
| size_t | len [2] |
| The lengths of the two slices. | |
| char * | ptr [2] |
| The pointers to the start of the two slices. | |
Claimed space for reading or writing directly into the internal ringbuffer of a channel.
All send/receive channel operations internally perform the following steps:
However, claims can be used directly to enable zero-copy operations. Instead of copying data into and out of the channel, that data is calculated or constructed directly inside the channel and read directly from the channel. Claims can be obtained from low-level *init() channel functions (such as mpmc_send_init) and committed through low-level *fini() channel functions (such as mpmc_send_fini).
This claimed space consists of one or two "slices" of its origin channel's internal ringbuffer; that is, one or two contiguous memory regions which can be read from or written to directly.
Since these slices refer to regions of the channel's internal ringbuffer, there is a chance that a claim may "wrap around" the end of the ringbuffer. For example, if the ringbuffer has a maximum capacity of 4 items, and 3 items are sent, then 1 item is received, there are two empty spaces that are free to be claimed for sending.
However, one of these spaces is at the end of the ringbuffer, while the other is at the start; these spaces are not contiguous. In this case, it is valid to claim those 2 spaces for sending, but since they are not contiguous, the claim will be "split" and the second slice of the claim will be populated.
A claim must be committed only into the channel it was obtained from.
| size_t claim::len[2] |
The lengths of the two slices.
If this claim is valid, [0] should always have a nonzero length. If this claim wraps around the origin channel's internal ringbuffer (that is to say, claim_is_split is true), [1] will have a nonzero length.
| char* claim::ptr[2] |
The pointers to the start of the two slices.
To meaningfully use these, they should be cast to a pointer to the expected type. For example, for a claim originating from a channel of doubles: