class BlobIdAllocator

Defined at line 48 of file ../../sdk/lib/iob/include/lib/iob/blob-id-allocator.h

Represents a thread-safe view into an IOBuffer region of "ID allocator"

discipline (ZX_IOB_DISCIPLINE_TYPE_ID_ALLOCATOR), used to map sized data

blobs to sequentially-allocated numeric IDs.

Suppose there are N mapped blobs. The memory is laid out as follows, with

copies of the blobs growing down and their corresponding bookkeeping indices

growing up:

--------------------------------

next available blob ID (4 bytes)

blob head offset (4 bytes)

----------------------------

blob 0 size (4 bytes) }

<

-- bookkeeping index

blob 0 offset (4 bytes) }

...

blob N-1 size (4 bytes)

blob N-1 offset (4 bytes)

----------------------------

zero-initialized memory

<

-- remaining bytes available

----------------------------

<

-- blob head offset

blob N-1

...

blob 0

--------------------------------

This class takes care of the atomic nuance required of accessing and updating

such a structure.

Public Methods

void BlobIdAllocator (cpp20::span<std::byte> bytes)

Constructs a view into an ID allocator IOBuffer region. If the provided

memory does not yet reflect this layout, Init() must be called before any

other method.

The provided memory must be at least 8-byte-aligned (for aligned atomic

access), and at least 8 bytes in size (so as to have enough room for the

header).

Defined at line 266 of file ../../sdk/lib/iob/include/lib/iob/blob-id-allocator.h

void BlobIdAllocator (cpp20::span<std::byte> bytes)

Constructs a view into an ID allocator IOBuffer region. If the provided

memory does not yet reflect this layout, Init() must be called before any

other method.

The provided memory must be at least 8-byte-aligned (for aligned atomic

access), and at least 8 bytes in size (so as to have enough room for the

header).

Defined at line 266 of file ../../sdk/lib/iob/include/lib/iob/blob-id-allocator.h

void Init (bool zero_fill)

Initializes the backing memory as an ID allocator region with no blobs yet

mapped. If the region is already known to be zero-filled, this part may be

skipped.

Defined at line 274 of file ../../sdk/lib/iob/include/lib/iob/blob-id-allocator.h

IterableView iterable ()

Provides an iterable view into the allocator, scoped to the lifetime of

this object.

Defined at line 291 of file ../../sdk/lib/iob/include/lib/iob/blob-id-allocator.h

uint32_t next_id ()

The next ID to be allocated.

Defined at line 294 of file ../../sdk/lib/iob/include/lib/iob/blob-id-allocator.h

fit::result<fit::failed, size_t> RemainingBytes ()

The remaining number of available bytes in the allocator (including those

that might be used for bookkeeping). fit::failed() is returned in the case

of an invalid header (see `AllocateError::kInvalidHeader` for more

detail).

Defined at line 300 of file ../../sdk/lib/iob/include/lib/iob/blob-id-allocator.h

fit::result<AllocateError, uint32_t> Allocate (cpp20::span<const std::byte> blob)

Attempts to store the provided blob and allocate its ID.

Defined at line 305 of file ../../sdk/lib/iob/include/lib/iob/blob-id-allocator.h

fit::result<AllocateError, uint32_t> Allocate (cpp20::span<const std::byte> blob)

Attempts to store the provided blob and allocate its ID.

Defined at line 305 of file ../../sdk/lib/iob/include/lib/iob/blob-id-allocator.h

template <typename Blob, typename CopyBlob>
fit::result<AllocateError, uint32_t> Allocate (CopyBlob && copy, Blob blob, size_t blob_size)

A variation of the allocation routine that abstracts the representation of

the supplied blob and the manner in which it is copied. This of particular

value to the use of this library in kernel, which requires care in dealing

with user-supplied memory.

`CopyBlob`, which performs the copy of blob to a specified destination, is

a callable of input signature `(Blob src, cpp20::span

<std

::byte> dest)` and

unspecified return type.

Defined at line 326 of file ../../sdk/lib/iob/include/lib/iob/blob-id-allocator.h

fit::result<BlobError, cpp20::span<const std::byte>> GetBlob (uint32_t id)

Returns the blob corresponding to a given ID.

Defined at line 376 of file ../../sdk/lib/iob/include/lib/iob/blob-id-allocator.h

Enumerations

enum AllocateError
Name Value
kInvalidHeader 0
kNonEmptyIndex 1
kOutOfMemory 2

The possible failure modes of Allocate().

Defined at line 51 of file ../../sdk/lib/iob/include/lib/iob/blob-id-allocator.h

enum BlobError
Name Value
kInvalidHeader 0
kUnallocatedId 1
kUncommittedIndex 2
kInvalidIndex 3

The possible failure modes of blob access, either via iteration via

IterableView or GetBlob().

Defined at line 68 of file ../../sdk/lib/iob/include/lib/iob/blob-id-allocator.h

Records