MMgr v2.3.0
Zero-heap memory manager in C11. One borrowed buffer, carved by asserted offset.
Loading...
Searching...
No Matches
memoria_anularis.h
Go to the documentation of this file.
1/* MMgr - Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2 * SPDX-License-Identifier: AGPL-3.0-or-later OR LicenseRef-Commercial OR LicenseRef-Educational
3 *
4 * Every use falls under AGPL-3.0-or-later unless you hold explicit permission, which is either a
5 * negotiated commercial licensing contract or an educator's license issued to you personally.
6 */
7/**
8 * @file memoria_anularis.h
9 * @brief Single-producer, single-consumer byte ring, a segment view over it, and loculus keepouts.
10 * @author dstroy0 (Douglas Quigg) <dquigg123@gmail.com>
11 * @date 2026-08-29
12 *
13 * @note Nothing of the implementation appears here. mmgr_ring is a run of opaque bytes, and no header
14 * a consumer can reach declares the state positioned into it. That lets the layout change with no
15 * recompile of a consumer against a different struct.
16 * @note The caller declares the ring and supplies the bytes; every index, mask and span is the ring's.
17 * @note Exactly one producer advances head and exactly one consumer advances tail. So ordering is
18 * all it takes, and no entry takes a lock or a read-modify-write on those two.
19 * @note No byte of the ring is ever scrubbed, and a drop leaves the loculus record alone. A
20 * restream can run again. Only mmgr_anular_init clears those records.
21 */
22#ifndef MMGR_MEMORIA_ANULARIS_H
23#define MMGR_MEMORIA_ANULARIS_H
24
25/** @addtogroup mod_anular
26 * @{ */
27
28#include "mmgr.h"
29
30EMBED_BEGIN_DECLS
31
32/**
33 * @brief A byte region a pinned loculus retains out: the storage, its extent, and how far a reader got.
34 *
35 * @note Carried here and not taken from spatium, and so this module reaches nothing outside config.
36 */
37typedef struct
38{
39 uint8_t *buf; /**< First byte of the region [BORROWS]. */
40 size_t bytes; /**< Bytes at buf. */
41 size_t read_offset; /**< How far a reader walked it, counted in bytes from buf. */
43
44/**
45 * @brief Size of the ring storage a caller declares, counted in size_t units.
46 *
47 * @note The implementation asserts its state fits inside this. A change there fails a build
48 * and does not run past a caller's object.
49 * @note The majority of the state is the keepout array, and so a raise of MMGR_RING_LOCULI grows it and may leave
50 * this short. The assertion below RingState in memoria_anularis.c is the single one that
51 * fails then.
52 * @note A build sets this before it includes this header, the same way it sets the loculus count.
53 */
54#ifndef MMGR_RING_WORDS
55
56#define MMGR_RING_WORDS 40u
57#endif
58
59/**
60 * @brief Loculi a mask can address, which is one bit per loculus in a machine word.
61 *
62 * @warning A build that declares more loculi than this has no bit left to name them. Wider masks, or
63 * a scan in their place, is what raises the ceiling. The assertion below fails until one of
64 * those happens.
65 */
66#define MMGR_RING_LOCULI_MAX EMBED_WORD_BITS
67
68/**
69 * @brief Loculi this build reserves, which a build may set before it includes this header.
70 *
71 * @note The keepout spans are the majority of the ring's state. A build with no use for the loculus view
72 * sets this to 0 and can then lower MMGR_RING_WORDS. This alone shrinks the state. The
73 * storage a caller declares follows MMGR_RING_WORDS alone.
74 * @note At 0, mmgr_anular_loculus_ready reports an empty mask, mmgr_anular_loculus_hold refuses every
75 * index, and mmgr_anular_loculus_keepout returns NULL. mmgr_anular_loculus_drop and
76 * mmgr_anular_loculus_mark leave both masks unchanged.
77 */
78#ifndef MMGR_RING_LOCULI
79
80#define MMGR_RING_LOCULI 8u
81#endif
82
83/**
84 * @brief Asserts the loculi a build declares fit in one machine word.
85 *
86 * @note The free and pinned masks are each one embed_word, one bit per loculus. A count past
87 * MMGR_RING_LOCULI_MAX has no bit to sit in. ring_loculus_bit in memoria_anularis.c
88 * builds that bit with a shift, and this bound retains the shift inside the word.
89 */
90EMBED_STATIC_ASSERT(
92 "the loculus masks are one machine word; widen them or fall back to a scan past MMGR_RING_LOCULI_MAX");
93
94/**
95 * @brief Reports whether count_ is a power of two.
96 *
97 * @param[in] count_ Count to test, either a byte capacity or a segment count.
98 * @return Non-zero when count_ has at max one bit set.
99 * @warning Also reports non-zero for a count_ of 0. mmgr_anular_init tests for 0 on a line of its own.
100 * @warning count_ appears twice in the expansion. An argument with a side effect runs twice.
101 */
102#define MMGR_RING_POW2(count_) (((count_) & ((count_) - 1u)) == 0u)
103
104/**
105 * @brief Wraps a ring offset back into a ring of capacity_ bytes.
106 *
107 * @param[in] index_ Offset to wrap, which can lie past the end of the buffer.
108 * @param[in] capacity_ Ring size in bytes, a power of two.
109 * @return index_ masked into the range 0 through capacity_ minus one.
110 * @warning Correct only because capacity_ is a power of two, which mmgr_anular_init enforces.
111 */
112#define MMGR_RING_WRAP(index_, capacity_) ((index_) & ((capacity_) - 1u))
113
114/**
115 * @brief Storage a caller declares for one ring, whose contents belong to the implementation.
116 *
117 * @note EMBED_ALIGN aligns opaque to size_t.
118 * @note From mmgr_anular_init onward these bytes hold the buffer that call received, which must
119 * outlive the ring [BORROWS].
120 * @warning The bytes carry no layout a consumer can reach. The definition of RingState is in
121 * memoria_anularis.c and nowhere else, and so the mmgr_anular_ entries are the
122 * only way into them.
123 */
124typedef struct
125{
126 EMBED_ALIGN(sizeof(size_t)) uint8_t opaque[MMGR_RING_WORDS * sizeof(size_t)]; /**< Private ring state. */
127} mmgr_ring;
128
129/**
130 * @brief Declares a ring's storage and claims the pool under it.
131 *
132 * @param[in] name_ Name of the ring.
133 * @param[in] pool_ Pool the ring covers, as ParsMemoriaeInternae or ParsMemoriaeExternum declared it
134 * [BORROWS].
135 * @note The claim retains one pool from two sets of records. A pool with a cellblock on it and then a ring
136 * arranged over it carries two sets of records over the same bytes. Each writes with no regard
137 * to the other, and nothing at run time reports it.
138 * @note A declaration, because MMGR_PARS_CLAIMED_ONCE emits an enumerator and an enumerator inside a
139 * function body is block scoped. Put at the mmgr_anular_init call it would shadow the
140 * cellblock's and never collide.
141 * @note Emits the storage and nothing in it. mmgr_anular_init positions the state into those bytes and
142 * still has to run, since it can refuse the sizes it receives.
143 * @note EMBED_PASS_MEMORY gives each pass of nvcc its own ring, as it gives each pass its own pool. A kernel
144 * reaches the ring in device memory, and host code reaches the one in host memory.
145 * @warning The pool appears here and again at mmgr_anular_init. Nothing holds those two to the
146 * same pool. A ring declared over one pool and initialized over another compiles.
147 */
148#define MemoriaAnularis(name_, pool_) \
149 MMGR_PARS_CLAIMED_ONCE(pool_); \
150 static EMBED_PASS_MEMORY mmgr_ring name_
151
152/**
153 * @brief Arguments for every mmgr_anular_ entry, each reading only the members it needs.
154 *
155 * @note Every entry but mmgr_anular_loculus_next reads ring. mmgr_anular_init reads buf, capacity,
156 * segment_count and segment_bytes on top of it.
157 * @note Members left unset are zero, and the entries that ignore them never read them.
158 */
159typedef struct
160{
161 mmgr_ring *const ring; /**< Ring to act on [BORROWS]. */
162 uint8_t *const buf; /**< Ring bytes, taken by mmgr_anular_init [BORROWS]. */
163 const size_t capacity; /**< Bytes at buf, non-zero, a power of two where segment_bytes is unset. */
164 const size_t segment_count; /**< Segments to divide the ring into, a power of two no larger than capacity. */
165 const size_t segment_bytes; /**< Bytes per segment where set, else capacity divided by segment_count. */
166 uint8_t *const dst; /**< Destination for read, read_byte and peek [BORROWS]. */
167 const uint8_t *const src; /**< Bytes put writes, or the region loculus_hold records [BORROWS]. */
168 const size_t bytes; /**< Byte count the call moves or records. */
169 const size_t offset; /**< Offset ahead of the tail that peek starts at. */
170 const size_t index; /**< Loculus or segment the call acts on. */
171 const embed_word mask; /**< Mask loculus_next picks the lowest set bit of. */
172 size_t *const out_index; /**< Segment index seg_next and seg_front write into [BORROWS]. */
174
175/**
176 * @brief Type of the anularis dispatch table.
177 *
178 * @note EMBED_TABLE_LAYOUT asserts the twenty members sit at consecutive EMBED_FUNCTION_POINTER_BYTES offsets, with
179 * nothing else.
180 * @note The twenty are mmgr_anular_init and three layers over the same bytes, and that call positions all
181 * three down. Seven members follow it for the byte ring, six for the segment view, and six for
182 * the loculi.
183 */
184typedef struct
185{
186 embed_bool (*init)(const AnularisCfg *args); /**< Lays a fresh ring into the caller's storage. */
187 size_t (*available)(const AnularisCfg *args); /**< Bytes ready for a read. */
188 size_t (*vacant)(const AnularisCfg *args); /**< Bytes still free to write. */
189 embed_bool (*read_byte)(const AnularisCfg *args); /**< Takes one byte and advances the tail. */
190 size_t (*read)(const AnularisCfg *args); /**< Takes up to bytes and advances the tail once. */
191 void (*peek)(const AnularisCfg *args); /**< Copies bytes out and leaves the tail in place. */
192 void (*consume)(const AnularisCfg *args); /**< Advances the tail past bytes. */
193 embed_bool (*put)(const AnularisCfg *args); /**< Writes a whole span, or refuses it entire. */
194 size_t (*seg_inflight)(const AnularisCfg *args); /**< Segments filled and not yet released. */
195 embed_bool (*seg_next)(const AnularisCfg *args); /**< Index of the segment the producer fills next. */
196 void (*seg_publish)(const AnularisCfg *args); /**< Makes the filled segment visible to the consumer. */
197 embed_bool (*seg_front)(const AnularisCfg *args); /**< Index of the segment the consumer takes next. */
198 void (*seg_release)(const AnularisCfg *args); /**< Frees the front segment. */
199 uint8_t *(*seg_at)(const AnularisCfg *args); /**< The contiguous span of one segment. */
200 embed_word (*loculus_ready)(const AnularisCfg *args); /**< Loculi that are free and not pinned. */
201 embed_iword (*loculus_next)(const AnularisCfg *args); /**< Lowest set bit of a mask, or -1. */
202 embed_bool (*loculus_hold)(const AnularisCfg *args); /**< Takes a loculus and records its keepout. */
203 const mmgr_ring_span *(*loculus_keepout)(const AnularisCfg *args); /**< The region a pinned loculus retains out. */
204 void (*loculus_drop)(const AnularisCfg *args); /**< Gives a loculus back and leaves its bytes alone. */
205 void (*loculus_mark)(const AnularisCfg *args); /**< Marks a loculus free. */
207EMBED_TABLE_LAYOUT(MemoriaAnularisNs, init, available, vacant, read_byte, read, peek, consume, put, seg_inflight,
208 seg_next, seg_publish, seg_front, seg_release, seg_at, loculus_ready, loculus_next, loculus_hold,
209 loculus_keepout, loculus_drop, loculus_mark);
210
211/**
212 * @brief Lays a fresh ring into args->ring, over the bytes at args->buf.
213 *
214 * @param[in,out] args Storage, bytes, capacity and segment count [BORROWS].
215 * @return EMBED_TRUE when the ring is ready, EMBED_FALSE when it refused a size.
216 * @note Refuses a capacity or a segment_count that is 0 or not a power of two, and a segment_count
217 * above capacity.
218 * @note Given args->segment_bytes, the capacity may be any size that holds segment_count segments of it.
219 * The ring then has segments and loculi and no byte stream: the vacant bytes read 0, a put fails
220 * and a read takes nothing. The segments' counters wrap by segment_count, and a segment's place is
221 * its index times its size. So no size needs to be a power of two.
222 * @note Marks every loculus free and none pinned, and clears the recorded keepouts.
223 * @warning args->ring and args->buf are both the caller's, and the ring retains args->buf [BORROWS].
224 * @warning Neither may be null, and nothing holds them there outside a MMGR_DEBUG_CHECKS build. A write
225 * goes through a null ring as soon as the sizes pass. A null buf goes in with no notice
226 * until the first move.
227 * @warning args->buf must carry the alignment the caller's own accesses need. This call does not
228 * align it.
229 */
230EMBED_HOST_DEVICE embed_bool mmgr_anular_init(const AnularisCfg *args);
231
232/**
233 * @brief Returns the bytes ready for a read.
234 *
235 * @param[in] args Ring to inspect [BORROWS].
236 * @return Distance from the tail to the head, wrapped into the ring.
237 * @warning The answer is only a snapshot. A concurrent producer may add more before the caller acts
238 * on it.
239 */
240EMBED_HOST_DEVICE size_t mmgr_anular_available(const AnularisCfg *args);
241
242/**
243 * @brief Returns the bytes still free to write.
244 *
245 * @param[in] args Ring to inspect [BORROWS].
246 * @return The capacity mmgr_anular_init received, less one, less the readable bytes.
247 * @note One byte always stays back, which retains a full ring apart from an empty one.
248 * @warning The answer is only a snapshot. A concurrent consumer may free more before the caller acts
249 * on it.
250 */
251EMBED_HOST_DEVICE size_t mmgr_anular_vacant(const AnularisCfg *args);
252
253/**
254 * @brief Takes one byte into args->dst and advances the tail past it.
255 *
256 * @param[in,out] args Ring and the destination byte [BORROWS].
257 * @return EMBED_TRUE when a byte came out, EMBED_FALSE when the ring was empty.
258 * @note Writes through args->dst only when it returns EMBED_TRUE.
259 * @note One byte per call, and so the cost is the call. A caller that draws a run of bytes
260 * wants mmgr_anular_read, which moves them a word at a time under one tail store.
261 * @warning args->dst must be writable for one byte.
262 */
263EMBED_HOST_DEVICE embed_bool mmgr_anular_read_byte(const AnularisCfg *args);
264
265/**
266 * @brief Takes up to args->bytes into args->dst and advances the tail once at the end.
267 *
268 * @param[in,out] args Ring, destination and the max to take [BORROWS].
269 * @return Bytes actually taken, which is 0 when the ring was empty.
270 * @note Moves the bytes in at max two runs, and so the wrap costs one extra move and not one per byte.
271 * @note Reads the tail once and publishes it once and not per byte.
272 * @warning args->dst must be writable for args->bytes.
273 */
274EMBED_HOST_DEVICE size_t mmgr_anular_read(const AnularisCfg *args);
275
276/**
277 * @brief Copies args->bytes from args->offset ahead of the tail into args->dst, and leaves the tail
278 * alone.
279 *
280 * @param[in,out] args Ring, destination, byte count and start offset [BORROWS].
281 * @note Moves the bytes in at max two runs, the same way mmgr_anular_read does.
282 * @warning Copies args->bytes whether or not that many arrived. Read mmgr_anular_available first.
283 * @warning An args->bytes above the ring's capacity stops there. Two runs cover one lap at max.
284 * @warning args->dst must be writable for args->bytes.
285 */
286EMBED_HOST_DEVICE void mmgr_anular_peek(const AnularisCfg *args);
287
288/**
289 * @brief Advances the tail past args->bytes.
290 *
291 * @param[in,out] args Ring and the byte count to drop [BORROWS].
292 * @warning Advances whether or not that many arrived. Read mmgr_anular_available first.
293 */
294EMBED_HOST_DEVICE void mmgr_anular_consume(const AnularisCfg *args);
295
296/**
297 * @brief Writes args->bytes of args->src into the ring, or refuses the whole span.
298 *
299 * @param[in,out] args Ring, the bytes to write and their count [BORROWS].
300 * @return EMBED_TRUE when the span went in, EMBED_FALSE when it would not fit.
301 * @note Checks the whole span against the vacant bytes first. A partial write never happens.
302 * @note Advances a local head across the wrap and publishes it once, and so no half span is ever visible.
303 * @warning args->src must be readable for args->bytes.
304 */
305EMBED_HOST_DEVICE embed_bool mmgr_anular_put(const AnularisCfg *args);
306
307/**
308 * @brief Returns the segments filled and not yet released.
309 *
310 * @param[in] args Ring to inspect [BORROWS].
311 * @return The distance between the claim and release counters.
312 * @warning The reads of the two counters come one after the other, and so the answer is only a snapshot. A publish
313 * or a release may land between the reads, or after both.
314 */
315EMBED_HOST_DEVICE size_t mmgr_anular_seg_inflight(const AnularisCfg *args);
316
317/**
318 * @brief Reports the index of the segment the producer fills next.
319 *
320 * @param[in,out] args Ring, and where to write the index [BORROWS].
321 * @return EMBED_TRUE with the index in args->out_index, EMBED_FALSE when every segment is
322 * in flight.
323 * @note Writes through args->out_index only when it returns EMBED_TRUE.
324 * @note The publish is separate. A half-filled segment is never visible to the consumer.
325 * @note A EMBED_FALSE can go stale the moment the consumer releases a segment. A EMBED_TRUE cannot,
326 * since releases only make room.
327 * @warning args->out_index must be writable.
328 */
329EMBED_HOST_DEVICE embed_bool mmgr_anular_seg_next(const AnularisCfg *args);
330
331/**
332 * @brief Makes the filled segment visible to the consumer.
333 *
334 * @param[in,out] args Ring to advance [BORROWS].
335 * @note Only the producer calls this. The read and the write of the counter are two steps, which needs no
336 * atomicity between them only because one side owns it.
337 * @warning Advances whether or not a segment filled. A publish with no mmgr_anular_seg_next to
338 * match puts more in flight than the ring holds, and that call then refuses
339 * until releases catch up.
340 */
341EMBED_HOST_DEVICE void mmgr_anular_seg_publish(const AnularisCfg *args);
342
343/**
344 * @brief Reports the index of the segment the consumer takes next.
345 *
346 * @param[in,out] args Ring, and where to write the index [BORROWS].
347 * @return EMBED_TRUE with the index in args->out_index, EMBED_FALSE when none is in flight.
348 * @note Writes through args->out_index only when it returns EMBED_TRUE.
349 * @note A EMBED_FALSE can go stale the moment the producer publishes a segment. A EMBED_TRUE cannot,
350 * since publishes only add.
351 * @warning args->out_index must be writable.
352 */
353EMBED_HOST_DEVICE embed_bool mmgr_anular_seg_front(const AnularisCfg *args);
354
355/**
356 * @brief Frees the front segment.
357 *
358 * @param[in,out] args Ring to advance [BORROWS].
359 * @note Segments release in the order of their claims.
360 * @note Only the consumer calls this. The read and the write of the counter are two steps, which needs no
361 * atomicity between them only because one side owns it.
362 * @warning Advances whether or not a segment was in flight. A release past the published count wraps
363 * the in-flight count and leaves mmgr_anular_seg_front with a segment on offer that never
364 * filled.
365 */
366EMBED_HOST_DEVICE void mmgr_anular_seg_release(const AnularisCfg *args);
367
368/**
369 * @brief Returns the contiguous span of segment args->index.
370 *
371 * @param[in] args Ring and the segment index [BORROWS].
372 * @return Its first byte inside the ring buffer [BORROWS].
373 * @note The span runs for the segment size mmgr_anular_init received, or else for the capacity divided
374 * by the segment_count it received.
375 * @warning Nothing checks args->index against the segment count, and no assertion covers it. An index
376 * at or past that count returns a pointer outside the ring's bytes.
377 */
378EMBED_HOST_DEVICE uint8_t *mmgr_anular_seg_at(const AnularisCfg *args);
379
380/**
381 * @brief Returns the loculi that are free and not pinned.
382 *
383 * @param[in] args Ring to inspect [BORROWS].
384 * @return The free mask with the pinned ones cleared, bounded to MMGR_RING_LOCULI.
385 * @note A loculus is takeable only when it is free and not pinned, and that leaves reuse safe.
386 * @warning The answer is only a snapshot. The reads of the two masks come one after the other, and a hold
387 * or a drop may land before the caller acts on it. mmgr_anular_loculus_hold settles that race,
388 * and refuses a loculus another caller took first.
389 */
390EMBED_HOST_DEVICE embed_word mmgr_anular_loculus_ready(const AnularisCfg *args);
391
392/**
393 * @brief Returns the index of the lowest set bit of args->mask.
394 *
395 * @param[in] args The mask to pick from [BORROWS].
396 * @return The index, or -1 when args->mask is empty.
397 * @note Counts and not scans, and branches on nothing but the empty mask.
398 * @note This reads only args->mask. This is the single one entry that never reaches the ring.
399 * @warning The mask passes as given. A bit at or above MMGR_RING_LOCULI comes back as its index,
400 * and that index names no loculus, and so mmgr_anular_loculus_hold refuses it.
401 */
402EMBED_HOST_DEVICE embed_iword mmgr_anular_loculus_next(const AnularisCfg *args);
403
404/**
405 * @brief Takes loculus args->index and records the args->bytes at args->src that it retains out.
406 *
407 * @param[in,out] args Ring, the loculus, and the region to record [BORROWS].
408 * @return EMBED_TRUE when this caller took it, EMBED_FALSE when args->index names none or
409 * another caller already holds it.
410 * @note The recorded region stays valid until mmgr_anular_loculus_drop. A reader walks it in place.
411 * @warning An out-of-range args->index names nothing, and so it reads as pinned and is never passed out.
412 * @warning The ring retains args->src and mmgr_anular_loculus_keepout passes it back, and so it must
413 * outlive the hold [BORROWS].
414 */
415EMBED_HOST_DEVICE embed_bool mmgr_anular_loculus_hold(const AnularisCfg *args);
416
417/**
418 * @brief Returns the region loculus args->index retains out.
419 *
420 * @param[in] args Ring and the loculus [BORROWS].
421 * @return The recorded span, or NULL when args->index is out of range [BORROWS].
422 * @note Passed back const. A reader walks it and leaves the ring's own record in place.
423 * @warning The const covers the span and not the bytes it names. buf is reachable as a writable
424 * pointer, though the region reached mmgr_anular_loculus_hold as const.
425 * @warning The record comes back for any loculus in range, pinned or not. A drop leaves it in place, and so
426 * afterwards it still names the last region that loculus recorded [BORROWS].
427 */
428EMBED_HOST_DEVICE const mmgr_ring_span *mmgr_anular_loculus_keepout(const AnularisCfg *args);
429
430/**
431 * @brief Gives loculus args->index back.
432 *
433 * @param[in,out] args Ring and the loculus [BORROWS].
434 * @note Leaves the recorded span and the bytes alone. A restream can run again.
435 * @note An out-of-range args->index names no bit and clears nothing, and a drop of a loculus with
436 * no pin does nothing.
437 */
438EMBED_HOST_DEVICE void mmgr_anular_loculus_drop(const AnularisCfg *args);
439
440/**
441 * @brief Marks loculus args->index free.
442 *
443 * @param[in,out] args Ring and the loculus [BORROWS].
444 * @note Sets the free bit. The pinned bit is mmgr_anular_loculus_drop's to clear, and a loculus is
445 * takeable only when it is free and not pinned.
446 * @note mmgr_anular_init sets the free bit for every loculus and no entry clears it, and so on a ring that
447 * call positioned down this changes nothing.
448 * @note An out-of-range args->index names no bit and sets nothing.
449 */
450EMBED_HOST_DEVICE void mmgr_anular_loculus_mark(const AnularisCfg *args);
451
452/**
453 * @brief Dispatch table instance named anularis, whose members are the mmgr_anular_ entries.
454 */
455EMBED_TABLE_STORAGE MemoriaAnularisNs anularis EMBED_UNUSED = {
456 .init = mmgr_anular_init,
457 .available = mmgr_anular_available,
458 .vacant = mmgr_anular_vacant,
459 .read_byte = mmgr_anular_read_byte,
460 .read = mmgr_anular_read,
461 .peek = mmgr_anular_peek,
462 .consume = mmgr_anular_consume,
463 .put = mmgr_anular_put,
464 .seg_inflight = mmgr_anular_seg_inflight,
465 .seg_next = mmgr_anular_seg_next,
466 .seg_publish = mmgr_anular_seg_publish,
467 .seg_front = mmgr_anular_seg_front,
468 .seg_release = mmgr_anular_seg_release,
469 .seg_at = mmgr_anular_seg_at,
470 .loculus_ready = mmgr_anular_loculus_ready,
471 .loculus_next = mmgr_anular_loculus_next,
472 .loculus_hold = mmgr_anular_loculus_hold,
473 .loculus_keepout = mmgr_anular_loculus_keepout,
474 .loculus_drop = mmgr_anular_loculus_drop,
475 .loculus_mark = mmgr_anular_loculus_mark,
476};
477
478EMBED_END_DECLS
479
480/** @} */
481
482#endif
EMBED_HOST_DEVICE embed_bool mmgr_anular_read_byte(const AnularisCfg *args)
Takes one byte into args->dst and advances the tail past it.
EMBED_HOST_DEVICE const mmgr_ring_span * mmgr_anular_loculus_keepout(const AnularisCfg *args)
Returns the region loculus args->index retains out.
EMBED_HOST_DEVICE size_t mmgr_anular_available(const AnularisCfg *args)
Returns the bytes ready for a read.
EMBED_HOST_DEVICE embed_bool mmgr_anular_loculus_hold(const AnularisCfg *args)
Takes loculus args->index and records the args->bytes at args->src that it retains out.
EMBED_HOST_DEVICE embed_bool mmgr_anular_put(const AnularisCfg *args)
Writes args->bytes of args->src into the ring, or refuses the whole span.
EMBED_HOST_DEVICE embed_bool mmgr_anular_seg_front(const AnularisCfg *args)
Reports the index of the segment the consumer takes next.
EMBED_HOST_DEVICE void mmgr_anular_peek(const AnularisCfg *args)
Copies args->bytes from args->offset ahead of the tail into args->dst, and leaves the tail alone.
#define MMGR_RING_WORDS
Size of the ring storage a caller declares, counted in size_t units.
EMBED_HOST_DEVICE size_t mmgr_anular_seg_inflight(const AnularisCfg *args)
Returns the segments filled and not yet released.
EMBED_HOST_DEVICE embed_bool mmgr_anular_seg_next(const AnularisCfg *args)
Reports the index of the segment the producer fills next.
EMBED_HOST_DEVICE embed_bool mmgr_anular_init(const AnularisCfg *args)
Lays a fresh ring into args->ring, over the bytes at args->buf.
EMBED_HOST_DEVICE size_t mmgr_anular_vacant(const AnularisCfg *args)
Returns the bytes still free to write.
EMBED_HOST_DEVICE size_t mmgr_anular_read(const AnularisCfg *args)
Takes up to args->bytes into args->dst and advances the tail once at the end.
EMBED_HOST_DEVICE void mmgr_anular_seg_release(const AnularisCfg *args)
Frees the front segment.
EMBED_HOST_DEVICE void mmgr_anular_loculus_drop(const AnularisCfg *args)
Gives loculus args->index back.
EMBED_HOST_DEVICE void mmgr_anular_loculus_mark(const AnularisCfg *args)
Marks loculus args->index free.
EMBED_HOST_DEVICE uint8_t * mmgr_anular_seg_at(const AnularisCfg *args)
Returns the contiguous span of segment args->index.
#define MMGR_RING_LOCULI
Loculi this build reserves, which a build may set before it includes this header.
static const MemoriaAnularisNs anularis
Dispatch table instance named anularis, whose members are the mmgr_anular_ entries.
EMBED_HOST_DEVICE void mmgr_anular_consume(const AnularisCfg *args)
Advances the tail past args->bytes.
EMBED_HOST_DEVICE void mmgr_anular_seg_publish(const AnularisCfg *args)
Makes the filled segment visible to the consumer.
#define MMGR_RING_LOCULI_MAX
Loculi a mask can address, which is one bit per loculus in a machine word.
EMBED_HOST_DEVICE embed_iword mmgr_anular_loculus_next(const AnularisCfg *args)
Returns the index of the lowest set bit of args->mask.
EMBED_HOST_DEVICE embed_word mmgr_anular_loculus_ready(const AnularisCfg *args)
Returns the loculi that are free and not pinned.
The embedded_types headers every module builds on.
Arguments for every mmgr_anular_ entry, each reading only the members it needs.
const size_t bytes
size_t *const out_index
const uint8_t *const src
mmgr_ring *const ring
const size_t segment_bytes
const size_t offset
const embed_word mask
const size_t index
const size_t segment_count
uint8_t *const buf
const size_t capacity
uint8_t *const dst
Type of the anularis dispatch table.
embed_bool(*) loculus_hold(const AnularisCfg *args)
embed_bool(*) put(const AnularisCfg *args)
embed_bool(*) seg_next(const AnularisCfg *args)
void(*) loculus_drop(const AnularisCfg *args)
void(*) seg_publish(const AnularisCfg *args)
embed_bool(*) read_byte(const AnularisCfg *args)
size_t(*) seg_inflight(const AnularisCfg *args)
size_t(*) read(const AnularisCfg *args)
embed_word(*) loculus_ready(const AnularisCfg *args)
size_t(*) vacant(const AnularisCfg *args)
size_t(*) available(const AnularisCfg *args)
void(*) seg_release(const AnularisCfg *args)
void(*) consume(const AnularisCfg *args)
void(*) peek(const AnularisCfg *args)
embed_bool(*) seg_front(const AnularisCfg *args)
void(*) loculus_mark(const AnularisCfg *args)
embed_bool(*) init(const AnularisCfg *args)
embed_iword(*) loculus_next(const AnularisCfg *args)
A byte region a pinned loculus retains out: the storage, its extent, and how far a reader got.
Storage a caller declares for one ring, whose contents belong to the implementation.
uint8_t opaque[MMGR_RING_WORDS *sizeof(size_t)]