Skip to content

<blake3pp/async_context.hpp>

EXPERIMENTAL. The context the senders of async_io.hpp run on, its options, and what a many-files operation reports per file. The run model and the lifetime rules are documented in async_io.hpp, which includes this header.

basic_io_context

class blake3pp::async::basic_io_context;

A driver, an arena of windows and the one thread that runs them. One thread may call run() or run_until_idle(); every other thread may call request_stop(), and may start operations on the context: a started operation joins the loop's list through an atomic push, and everything it does -- the open, the plan, the reads -- happens on the running thread from its first round. Operations complete on the running thread, inside the run call, which is also the only place a receiver of one of these senders is ever invoked.

Parameter
Budget What a window's part table may take. It is the context's rather than the call's because the context owns the tables; see stack_budget.

Types

scheduler_type

using scheduler_type = blake3pp::detail::driver_scheduler<blake3pp::detail::io_driver>;

What continues_on() takes to come back to this context.

Member functions

basic_io_context

explicit basic_io_context(const io_context_options &opts={});

basic_io_context

basic_io_context(const basic_io_context &)=delete;

operator=

basic_io_context & operator=(const basic_io_context &)=delete;

~basic_io_context

~basic_io_context();

scheduler

scheduler_type scheduler() noexcept;

Where a stage comes back to when it has to touch the driver again.

run

void run();

Runs until request_stop() has been called and nothing is owed. With nothing started it blocks until request_stop(), which is what a thread dedicated to the context wants; run_until_idle() is the call for a thread that has other work.

run_until_idle

void run_until_idle();

Runs until no operation is in flight, then returns. A context with nothing started returns immediately.

run_until

void run_until(const std::atomic<bool> &done);

Runs until done reads true, whichever thread sets it; other operations may still be in flight when it returns. What sync_wait() drives. The flag is atomic because a composed sender's last stage may complete off this thread, and whoever sets it must then wake this context -- which is what sync_wait()'s receiver does.

windows

unsigned windows() const noexcept;

How many windows the arena holds.

request_stop

void request_stop() noexcept;

Asks every started operation to stop and wakes the running thread. Safe from any thread, as starting an operation is.

stop_requested

bool stop_requested() const noexcept;

Whether a stop has been requested. It stays set until a run returns with no operation live or waiting to be adopted, and clears there.

no_start

struct blake3pp::async::basic_io_context::no_start;

Member functions

operator()

void operator()() const noexcept;

rounds

struct blake3pp::async::basic_io_context::rounds;

Data members

done

detail::pipeline_node * done = nullptr;

owed

unsigned owed = 0;

file_options

struct blake3pp::async::file_options;

Knobs for async_update_file(). The window geometry and the read mechanism are the context's (io_context_options).

Data members

io

io_mode io = io_mode::direct;

io_mode::buffered overrides the context's io_mode::direct for this file; io_mode::direct leaves the context's choice in place.

file_outcome

struct blake3pp::async::file_outcome;

How one file of a many-files operation ended. The outcome is reported to the caller's callback; the operation itself completes once, after every file has an outcome.

Member functions

ok

bool ok() const noexcept;

Whether the hasher holds the whole file.

Data members

error

std::error_code error {};

The error_code channel: an open or a read that failed.

exception

std::exception_ptr exception {};

The exception channel: everything else that went wrong.

stopped

bool stopped = false;

The file was stopped, or never started because a stop came first.

hash_options

struct blake3pp::async::hash_options;

Knobs for async_hash_file(): file_options, plus the hasher the operation builds.

Data members

a

arch a = arch::auto_detect;

The SIMD variant of the hasher.

mode

hash_mode mode {};

Plain, keyed or key-derivation mode, as for hash_file_options. The sender copies it, key or context included, so nothing it names has to outlive the call.

io

io_mode io = io_mode::direct;

As for file_options.

io_context_options

struct blake3pp::async::io_context_options;

How much storage a context takes and how it opens files. The geometry is the context's, not the call's: the arena is one allocation shared by every operation, so the window size and the number of windows are settled when the context is built. A single operation may hold at most queue_depth of them at once, which is what keeps one large file from starving the rest.

Data members

window_bytes

std::size_t window_bytes = blake3pp::detail::default_window_bytes;

Bytes per window, 8 MiB by default; rounded down to a power-of-2 multiple of chunk_size, minimum 64 KiB.

queue_depth

unsigned queue_depth = blake3pp::detail::default_queue_depth;

Windows one operation may hold at once, four by default; clamped to [2, 256].

windows

unsigned windows = 0;

Windows in the shared arena, at window_bytes each. Zero means what the plan asks for, which at the defaults is 16 windows and so a 128 MiB arena -- several operations' worth already. Clamped to the same ceiling as queue_depth, because every window costs the same window_bytes whether it was asked for as a count or as a budget.

arena_bytes

std::size_t arena_bytes = 0;

The arena as a byte budget instead: when non-zero, the window count is this divided by the window size, at least queue_depth and under the same ceiling, and windows is ignored. The budget is what a caller knows; how many windows it buys depends on the window size.

io

io_mode io = io_mode::direct;

See io_mode; per file. A file whose window grid is unaligned is opened buffered whatever this says, because every window after an unaligned one starts unaligned too.

submit

submit_mode submit = submit_mode::offload;

See file_io_options.

windows_api

windows_engine windows_api = windows_engine::ioring;

Windows only; see windows_engine. The engaged rung is reported after the fact and names which one ran.

many_files_options

struct blake3pp::async::many_files_options;

Knobs for async_update_files().

Data members

in_flight

unsigned in_flight = 0;

Files in flight at once. Zero means as many as the context has windows, so that every file in flight can hold a window; the context's window admission shares them out from there. A file smaller than one window is one read, so this is the count that keeps a device and a pool busy over many small files.

io

io_mode io = io_mode::direct;

As for file_options, for every file of the batch.

Types

io_context

using io_context = basic_io_context<default_stack_budget>;

The context, with the default part-table budget.