LLFIO
v2.00
|
An interface to a state for an i/o operation scheduled against an i/o multiplexer. More...
#include "byte_io_multiplexer.hpp"
Classes | |
struct | lock_guard |
Used by the visitor to control the state lock. More... | |
Public Member Functions | |
virtual void * | invoke (function_ptr< void *(io_operation_state_type)> c) const noexcept=0 |
Invoke the callable with the per-i/o state lock held, if any. | |
virtual io_operation_state_type | current_state () const noexcept=0 |
Used to retrieve the current state of the i/o operation. | |
virtual io_result< buffers_type > | get_completed_read () &&noexcept=0 |
After an i/o operation has finished, can be used to retrieve the result if the visitor did not. | |
virtual io_result< const_buffers_type > | get_completed_write_or_barrier () &&noexcept=0 |
After an i/o operation has finished, can be used to retrieve the result if the visitor did not. | |
virtual io_operation_state * | relocate_to (byte *to) noexcept=0 |
Relocate the state to new storage, clearing the original state. Terminates the process if the state is in use. | |
Public Attributes | |
byte_io_handle * | h {nullptr} |
The i/o handle the i/o operation is upon. | |
io_operation_state_visitor * | visitor {nullptr} |
The state visitor supplied when the operation was initialised. | |
Protected Member Functions | |
constexpr | io_operation_state (byte_io_handle *_h, io_operation_state_visitor *_visitor) |
virtual void | _lock () noexcept |
virtual void | _unlock () noexcept |
Friends | |
struct | lock_guard |
An interface to a state for an i/o operation scheduled against an i/o multiplexer.
You will need to ask the i/o multiplexer for how much storage, and alignment, is required to store one of these using byte_io_multiplexer::io_state_requirements()
. Be aware that for some i/o multiplexers, quite a lot of storage (e.g. > 1Kb for IOCP on Windows) may be required. You can either preallocate i/o operation states for later use, or use other determinism-maintaining tricks to avoid dynamic memory allocation for i/o operation states.
When you construct one of these using byte_io_multiplexer::init_io_operation()
, you must pass in a pointer to a io_operation_state_visitor
. This visitor will be called whenever the lifecycle for the i/o state is about to change (it is called just before .current_state()
is changed, and with any per-state locks held).
The lifecycle for one of these is as follows:
byte_io_multiplexer::init_io_operation()
has been called to initialise the i/o operation state. You can now no longer relocate the i/o operation state in memory until the corresponding *_finished()
visitor function is called.*_initiated()
function. This may occur in byte_io_multiplexer::init_io_operation()
, in byte_io_multiplexer::flush_inited_io_operations()
, or never at all if the i/o completed immediately.*_completed()
visitor function. This can occur at any time, and can be called by any kernel thread, if the i/o multiplexer in use is used by multiple kernel threads. The completion functions are usually invoked by somebody calling byte_io_multiplexer::check_io_operation()
or byte_io_multiplexer::check_for_any_completed_io()
, but may also be called by an asynchronous system agent.byte_io_multiplexer::init_io_operation()
returns until the corresponding *_finished()
visitor function is called.