You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.4 KiB
60 lines
2.4 KiB
const Config = @import("./config.zig").Config; |
|
|
|
/// Compilation environment and configuration. |
|
/// |
|
/// An engine is typically global in a program and contains all the |
|
/// configuration necessary for compiling wasm code. From an engine you'll |
|
/// typically create a `Store`. Engines are created with `initDefault` or |
|
/// `initWithConfig`. |
|
/// |
|
/// An engine is safe to share between threads. Multiple stores can be created |
|
/// within the same engine with each store living on a separate thread. |
|
/// Typically you'll create one `Engine` for the lifetime of your program. |
|
/// |
|
/// Engines are reference counted internally so `deinit` can be called at any |
|
/// time after a `Store` has been created from one. |
|
pub const Engine = opaque { |
|
/// Creates a new engine with the default configuration. |
|
/// |
|
/// The object returned is owned by the caller and will need to be deleted |
|
/// with `deinit`. This may return `error.ModuleInit` if the engine could |
|
/// not be allocated. |
|
pub fn initDefault() !*Engine { |
|
return wasm_engine_new() orelse error.ModuleInit; |
|
} |
|
|
|
/// Creates a new engine with the specified configuration. |
|
/// |
|
/// This function will take ownership of the configuration specified |
|
/// regardless of the outcome of this function. You do not need to call |
|
/// `Config.deinit` on the argument. The object returned is owned by the |
|
/// caller and will need to be deleted with `deinit`. This may return |
|
/// `error.ModuleInit` if the engine could not be allocated. |
|
pub fn initWithConfig(config: *Config) !*Engine { |
|
return wasm_engine_new_with_config(config) orelse error.ModuleInit; |
|
} |
|
|
|
pub fn deinit(self: *Engine) void { |
|
wasm_engine_delete(self); |
|
} |
|
|
|
/// Increments the engine-local epoch variable. |
|
/// |
|
/// This function will increment the engine's current epoch which can be |
|
/// used to force WebAssembly code to trap if the current epoch goes |
|
/// beyond the `Store` configured epoch deadline. |
|
/// |
|
/// This function is safe to call from any thread, and it is also |
|
/// async-signal-safe. |
|
/// |
|
/// See also `Config.epoch_interruption_set`. |
|
pub fn increment_epoch(self: *Engine) void { |
|
wasmtime_engine_increment_epoch(self); |
|
} |
|
|
|
extern "c" fn wasm_engine_new() ?*Engine; |
|
extern "c" fn wasm_engine_new_with_config(*Config) ?*Engine; |
|
extern "c" fn wasm_engine_delete(*Engine) void; |
|
|
|
extern "c" fn wasmtime_engine_increment_epoch(*Engine) void; |
|
};
|
|
|