1 /**
2  * \file wasmtime/engine.hh
3  */
4 
5 #ifndef WASMTIME_ENGINE_HH
6 #define WASMTIME_ENGINE_HH
7 
8 #include <memory>
9 #include <wasmtime/config.hh>
10 #include <wasmtime/engine.h>
11 #include <wasmtime/helpers.hh>
12 
13 namespace wasmtime {
14 
15 /**
16  * \brief Global compilation state in Wasmtime.
17  *
18  * Created with either default configuration or with a specified instance of
19  * configuration, an `Engine` is used as an umbrella "session" for all other
20  * operations in Wasmtime.
21  */
22 class Engine {
23 /// bridging wasm.h vs wasmtime.h conventions
24 #define wasm_engine_clone wasmtime_engine_clone
25   WASMTIME_CLONE_WRAPPER(Engine, wasm_engine);
26 #undef wasm_engine_clone
27 
28   /// \brief Creates an engine with default compilation settings.
Engine()29   Engine() : ptr(wasm_engine_new()) {}
30   /// \brief Creates an engine with the specified compilation settings.
Engine(Config config)31   explicit Engine(Config config)
32       : ptr(wasm_engine_new_with_config(config.capi_release())) {}
33 
34   /// \brief Increments the current epoch which may result in interrupting
35   /// currently executing WebAssembly in connected stores if the epoch is now
36   /// beyond the configured threshold.
increment_epoch() const37   void increment_epoch() const { wasmtime_engine_increment_epoch(ptr.get()); }
38 
39   /// \brief Returns whether this engine is using Pulley for execution.
is_pulley() const40   void is_pulley() const { wasmtime_engine_is_pulley(ptr.get()); }
41 };
42 
43 } // namespace wasmtime
44 
45 #endif // WASMTIME_ENGINE_HH
46