27#ifndef MMGR_MEMORIA_VECTOR_H
28#define MMGR_MEMORIA_VECTOR_H
45#ifndef MMGR_VECTOR_CHUNK_BYTES
47#define MMGR_VECTOR_CHUNK_BYTES 64u
54#define MMGR_VECTOR_CLAIM_BITS ((size_t)(8u * sizeof(embed_atomic_usize)))
62#define MMGR_VECTOR_CLAIM_WORDS(limit_) (((size_t)(limit_) + MMGR_VECTOR_CLAIM_BITS - 1u) / MMGR_VECTOR_CLAIM_BITS)
102#define MemoriaVector(name_, element_, limit_, owner_) \
103 EMBED_STATIC_ASSERT((size_t)(limit_) > 0u, #name_ " has a ceiling of 0 elements"); \
104 EMBED_STATIC_ASSERT((size_t)(limit_) <= (MMGR_CARCER_BYTES_MAX / sizeof(element_)), \
105 #name_ " has a ceiling whose cell passes MMGR_CARCER_BYTES_MAX"); \
106 EMBED_STATIC_ASSERT((MMGR_ALIGN_BYTES % EMBED_ALIGNOF(element_)) == 0u, \
107 #name_ " has an element whose alignment does not divide MMGR_ALIGN_BYTES"); \
108 static EMBED_PASS_MEMORY embed_atomic_usize mmgr_vector_claimed_##name_[MMGR_VECTOR_CLAIM_WORDS(limit_)]; \
109 static EMBED_PASS_MEMORY VectorRecord mmgr_vector_record_##name_ = { \
110 EMBED_ATOMIC_INIT(0u), EMBED_ATOMIC_INIT(0u), EMBED_ATOMIC_INIT(0u), sizeof(element_), \
111 (size_t)(limit_), &(owner_), mmgr_vector_claimed_##name_}; \
112 static EMBED_PASS_MEMORY VectorRecord *const name_ = &mmgr_vector_record_##name_
120#define MMGR_VECTOR_THROUGH(guard_) \
121 .take = (guard_).movable_buf_alloc, .give = (guard_).movable_buf_release, .read = (guard_).movable_buf_read, \
122 .write = (guard_).movable_buf_write
159EMBED_TABLE_LAYOUT(
MemoriaVectorNs, at, set, push_back, pop_back, size, release);
struct CarcerMovableEntry CarcerMovableEntry
The identity a movable cell's taker holds: a const pointer to the cell's entry in the cellblock's tra...
EMBED_HOST_DEVICE embed_bool mmgr_vector_set(const MemoriaVectorCfg *args)
Copies the element at args->src to args->index.
EMBED_HOST_DEVICE embed_bool mmgr_vector_release(const MemoriaVectorCfg *args)
Gives the cell of the vector back, and leaves the vector with no element.
EMBED_HOST_DEVICE embed_bool mmgr_vector_push_back(const MemoriaVectorCfg *args)
Appends the element at args->src.
static const MemoriaVectorNs memoria_vector
Dispatch table instance named memoria_vector, whose members are the mmgr_vector_ entries.
#define MMGR_VECTOR_CHUNK_BYTES
Bytes of the buffer on the stack that a growth copies the elements through, which a build may set bef...
EMBED_HOST_DEVICE embed_bool mmgr_vector_pop_back(const MemoriaVectorCfg *args)
Removes the last element and copies it to args->dst.
EMBED_HOST_DEVICE embed_bool mmgr_vector_at(const MemoriaVectorCfg *args)
Copies the element at args->index to args->dst.
EMBED_HOST_DEVICE size_t mmgr_vector_size(const MemoriaVectorCfg *args)
Returns the count of elements.
A prison site: a caller's storage divided into cellblocks, with the warden that holds them.
The embedded_types headers every module builds on.
Arguments for the calls that reach a movable cell's bytes, each of which reads the members it names.
Asserts MMGR_CARCER_ALIGN is a power of two.
Arguments for every mmgr_vector_ entry, each reading only the members it needs.
VectorRecord *const vector
embed_bool(*const) write(const CarcerMovableCfg *args)
embed_bool(*const) give(const CarcerMovableEntry *cell, const CellOwner *owner)
const CarcerMovableEntry *(*const) take(size_t size, const CellOwner *owner)
embed_bool(*const) read(const CarcerMovableCfg *args)
Type of the vector dispatch table.
embed_bool(*) pop_back(const MemoriaVectorCfg *args)
embed_bool(*) release(const MemoriaVectorCfg *args)
embed_bool(*) set(const MemoriaVectorCfg *args)
embed_bool(*) push_back(const MemoriaVectorCfg *args)
embed_bool(*) at(const MemoriaVectorCfg *args)
size_t(*) size(const MemoriaVectorCfg *args)
The record of one vector, which its token names.
const CellOwner *const *const owner
embed_atomic_usize *const claimed
embed_atomic_usize capacity