Asynchronous completion objects
include/thread/async_completion.h View source View on GitHubStructs
Section titled “Structs”async_completion
Section titled “async_completion” struct async_completion (2 fields) source
TODO
I wrote this all out and never used it. this is a nice wrapper around using APCs vs callbacks via worker for async callbacks, and it would be great if I could start using the pattern
§
union §
struct We use this structure to store data BEFORE the APC is enqueued. This is so that we can save space in this very frequently instantiated structure, and reuse space instead of using more
§
apc_func_t apc_func_internal §
void *ctx §
enum async_completion_type type NOTE
must match the position of *owner in struct apc.
This is used here so that we don’t use extra space In prepare():
apc_init(&ac->apc);Later on… ac->type = type; // APC is ‘0’, so it’s fine to overwrite // *owner
In complete(): enum async_completion_type type = ac->type;
check type and act on it
§
void (*callback)(struct async_completion *) async_completion_type
Section titled “async_completion_type” enum async_completion_type (2 variants) source
Functions
Section titled “Functions”async_complete
Section titled “async_complete”void async_complete(struct async_completion *ac, void *ctx) source async_apc_callback_internal
Section titled “async_apc_callback_internal”void async_apc_callback_internal(
struct apc_context *apc_ctx,
void *arg
) source async_prepare
Section titled “async_prepare”void async_prepare(
struct async_completion *ac,
void (*cb)(
struct async_completion *),
enum async_completion_type type
) source Macros
Section titled “Macros”ASYNC_CTX_NONE
Section titled “ASYNC_CTX_NONE”#define ASYNC_CTX_NONE NULL source