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 12 namespace wasmtime { 13 14 /** 15 * \brief Global compilation state in Wasmtime. 16 * 17 * Created with either default configuration or with a specified instance of 18 * configuration, an `Engine` is used as an umbrella "session" for all other 19 * operations in Wasmtime. 20 */ 21 class Engine { 22 friend class Store; 23 friend class Module; 24 friend class Linker; 25 26 struct deleter { 27 void operator()(wasm_engine_t *p) const { wasm_engine_delete(p); } 28 }; 29 30 std::unique_ptr<wasm_engine_t, deleter> ptr; 31 32 public: 33 /// \brief Creates an engine with default compilation settings. 34 Engine() : ptr(wasm_engine_new()) {} 35 /// \brief Creates an engine with the specified compilation settings. 36 explicit Engine(Config config) 37 : ptr(wasm_engine_new_with_config(config.ptr.release())) {} 38 39 /// Copies another engine into this one. 40 Engine(const Engine &other) : ptr(wasmtime_engine_clone(other.ptr.get())) {} 41 /// Copies another engine into this one. 42 Engine &operator=(const Engine &other) { 43 ptr.reset(wasmtime_engine_clone(other.ptr.get())); 44 return *this; 45 } 46 ~Engine() = default; 47 /// Moves resources from another engine into this one. 48 Engine(Engine &&other) = default; 49 /// Moves resources from another engine into this one. 50 Engine &operator=(Engine &&other) = default; 51 52 /// \brief Increments the current epoch which may result in interrupting 53 /// currently executing WebAssembly in connected stores if the epoch is now 54 /// beyond the configured threshold. 55 void increment_epoch() const { wasmtime_engine_increment_epoch(ptr.get()); } 56 57 /// \brief Returns whether this engine is using Pulley for execution. 58 void is_pulley() const { wasmtime_engine_is_pulley(ptr.get()); } 59 60 /// \brief Returns the underlying C API pointer. 61 const wasm_engine_t *capi() const { return ptr.get(); } 62 63 /// \brief Returns the underlying C API pointer. 64 wasm_engine_t *capi() { return ptr.get(); } 65 }; 66 67 } // namespace wasmtime 68 69 #endif // WASMTIME_ENGINE_HH 70