📨 chic
0.0.0
Realtime-safe channels in C
Toggle main menu visibility
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
26
struct
claim
{
37
size_t
seq
;
38
40
size_t
len
[2];
41
43
char
*
ptr
[2];
44
};
45
51
#define claim_cast(C, T, I) ((T)*)((C)->ptr[I])
52
54
static
inline
bool
claim_is_empty
(
const
struct
claim
*it) {
55
return
it->
len
[0] == 0;
56
}
57
59
static
inline
bool
claim_is_split
(
const
struct
claim
*it) {
60
return
it->
len
[1] != 0;
61
}
62
64
static
inline
size_t
claim_len
(
const
struct
claim
*it) {
65
return
it->
len
[0] + it->
len
[1];
66
}
67
69
static
inline
void
claim_consume
(
struct
claim
*it) {
70
#ifdef NDEBUG
71
// Sufficient to ensure claim_is_empty(it) == true
72
it->
len
[0] = 0;
73
#else
74
*it = (
struct
claim
){0};
75
#endif
76
}
77
78
#ifdef __cplusplus
79
}
80
#endif
claim_consume
static void claim_consume(struct claim *it)
Consumes a claim, such that committing it has no effect.
Definition
claim.h:69
claim_is_empty
static bool claim_is_empty(const struct claim *it)
Checks if a claim is empty.
Definition
claim.h:54
claim_is_split
static bool claim_is_split(const struct claim *it)
Checks if a claim is split between two contiguous regions.
Definition
claim.h:59
claim_len
static size_t claim_len(const struct claim *it)
Gets the total length of the claimed space in a claim.
Definition
claim.h:64
claim
Claimed space for reading or writing directly into the internal ringbuffer of a channel.
Definition
claim.h:26
claim::ptr
char * ptr[2]
The pointers to the start of the two slices.
Definition
claim.h:43
claim::seq
size_t seq
The sequence number of this claim.
Definition
claim.h:37
claim::len
size_t len[2]
The lengths of the two slices.
Definition
claim.h:40
include
claim.h
Generated on
for 📨 chic by
1.17.0