Skip to content

Asynchronous completion objects

include/thread/async_completion.h View source View on GitHub
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 apc apc
§ 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
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

§ struct thread *thread
§ void (*callback)(struct async_completion *)
enum async_completion_type (2 variants) source
§ ASYNC_COMPLETION_APC = 0
§ ASYNC_COMPLETION_WORKER = 1
void async_complete(struct async_completion *ac, void *ctx)
source
void async_apc_callback_internal(
    struct apc_context *apc_ctx,
    void *arg
)
source
void async_prepare(
    struct async_completion *ac,
    void (*cb)(
        struct async_completion *),
    enum async_completion_type type
)
source
#define ASYNC_CTX_NONE NULL
source