📨 chic 0.0.0
Realtime-safe channels in C
Loading...
Searching...
No Matches
claim.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 <stddef.h>
12#ifdef __cplusplus
13 extern "C" {
14#elif __STDC_VERSION__ < 202311L
15 #include <stdbool.h>
16#endif
17
20
66struct claim {
77 size_t seq;
78
85 size_t len[2];
86
100 char *ptr[2];
101};
102
104static inline bool claim_is_empty(const struct claim *it) {
105 return it->len[0] == 0;
106}
107
109static inline bool claim_is_split(const struct claim *it) {
110 return it->len[1] != 0;
111}
112
114static inline size_t claim_len(const struct claim *it) {
115 return it->len[0] + it->len[1];
116}
117
119static inline void claim_consume(struct claim *it) {
120 #ifdef NDEBUG
121 // Sufficient to ensure claim_is_empty(it) == true
122 it->len[0] = 0;
123 #else
124 *it = (struct claim){0};
125 #endif
126}
127
128#ifdef __cplusplus
129 }
130#endif
static void claim_consume(struct claim *it)
Consumes a claim, such that committing it has no effect.
Definition claim.h:119
static bool claim_is_empty(const struct claim *it)
Checks if a claim is empty.
Definition claim.h:104
static bool claim_is_split(const struct claim *it)
Checks if a claim is split between two contiguous regions.
Definition claim.h:109
static size_t claim_len(const struct claim *it)
Gets the total length of the claimed space in a claim.
Definition claim.h:114
Claimed space for reading or writing directly into the internal ringbuffer of a channel.
Definition claim.h:66
char * ptr[2]
The pointers to the start of the two slices.
Definition claim.h:100
size_t seq
The sequence number of this claim.
Definition claim.h:77
size_t len[2]
The lengths of the two slices.
Definition claim.h:85