-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Async support in the C API #7106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
a60ad97
c13ba81
42f38d0
7f06025
4739b6b
eaf2bb6
2a7d830
6d183a4
d09d856
aa5e91f
9271efb
574de30
66da177
44d9cac
fadb7f3
855da7d
549b655
58894ca
e6e8870
8aee8d3
3c7616c
ca20623
9e7054a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,5 @@ foo | |
publish | ||
vendor | ||
examples/build | ||
examples/.cache | ||
*.coredump |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
#include <wasmtime/error.h> | ||
#include <wasmtime/store.h> | ||
#include <wasmtime/extern.h> | ||
#include <wasmtime/instance.h> | ||
#include <wasmtime/module.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
|
@@ -119,6 +121,23 @@ WASM_API_EXTERN wasmtime_error_t* wasmtime_linker_define_func( | |
void (*finalizer)(void*) | ||
); | ||
|
||
/** | ||
* \brief Defines a new async function in this linker. | ||
* | ||
* This function behaves similar to #wasmtime_linker_define_func, except it supports async | ||
* callbacks | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This I think warrants a bit of expansion and more explanation. This might be another good use case for an
Basically I think it's ok for the docs on individual functions to be a bit terse, but there are a huge number of gotchas with getting async right in C. There's no protection lifetime-wise when it's most critically required for async so I'd want to make sure that we at least have some longer-form documentation explaining some of the hazards and what embedders need to consider when designing their own async support. If you're up for starting the documentation I can try to help fill it in too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Not that my embedding does this - but is it safe to call back into the VM from a async host function? That maybe a reason to not add this check. I took a stab at the documentation. I will admit documentation is not my strong suit so help is appreciated (or I'm happy to rubber duck/review a followup PR on improving the documentation). |
||
WASM_API_EXTERN wasmtime_error_t *wasmtime_linker_define_async_func( | ||
wasmtime_linker_t *linker, | ||
const char *module, | ||
size_t module_len, | ||
const char *name, | ||
size_t name_len, | ||
const wasm_functype_t *ty, | ||
wasmtime_func_async_callback_t cb, | ||
void *data, | ||
void (*finalizer)(void *)); | ||
|
||
/** | ||
* \brief Defines a new function in this linker. | ||
* | ||
|
@@ -218,6 +237,23 @@ WASM_API_EXTERN wasmtime_error_t* wasmtime_linker_instantiate( | |
wasm_trap_t **trap | ||
); | ||
|
||
/** | ||
* \brief Instantiates a #wasm_module_t with the items defined in this linker for an async store. | ||
* | ||
* This is the same as #wasmtime_linker_instantiate but used for async stores | ||
* (which requires functions are called asynchronously). The returning #wasmtime_call_future_t | ||
* must be polled using #wasmtime_call_future_poll, and is owned and must be deleted using #wasmtime_call_future_delete. | ||
* The future's results are retrieved using `wasmtime_call_future_get_results after polling has returned true marking | ||
* the future as completed. | ||
rockwotj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* All arguments to this function must outlive the returned future. | ||
*/ | ||
WASM_API_EXTERN wasmtime_call_future_t *wasmtime_linker_instantiate_async( | ||
const wasmtime_linker_t *linker, | ||
wasmtime_context_t *store, | ||
const wasmtime_module_t *module, | ||
wasmtime_instance_t *instance); | ||
|
||
/** | ||
* \brief Defines automatic instantiations of a #wasm_module_t in this linker. | ||
* | ||
|
Uh oh!
There was an error while loading. Please reload this page.