Skip to content
This repository was archived by the owner on Dec 16, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion source/extensions/common/wasm/wasm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,16 @@ bool Wasm::initialize(const std::string& code, bool allow_precompiled) {
return true;
}

Context* Wasm::getOrCreateRootContext(const PluginSharedPtr& plugin) {
auto root_context = getRootContext(plugin->root_id_);
if (!root_context) {
auto context = std::make_unique<Context>(this, plugin);
root_context = context.get();
root_contexts_[plugin->root_id_] = std::move(context);
}
return root_context;
}

void Wasm::startVm(Context* root_context) {
/* Call "_start" function, and fallback to "__wasm_call_ctors" if the former is not available. */
if (_start_) {
Expand Down Expand Up @@ -611,7 +621,7 @@ WasmHandleSharedPtr getOrCreateThreadLocalWasm(WasmHandleSharedPtr base_wasm,
Event::Dispatcher& dispatcher) {
auto wasm_handle = getThreadLocalWasmPtr(base_wasm->wasm()->vm_key());
if (wasm_handle) {
auto root_context = wasm_handle->wasm()->start(plugin);
auto root_context = wasm_handle->wasm()->getOrCreateRootContext(plugin);
if (!wasm_handle->wasm()->configure(root_context, plugin, configuration)) {
throw WasmException("Failed to configure WASM code");
}
Expand Down
1 change: 1 addition & 0 deletions source/extensions/common/wasm/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class Wasm : public Logger::Loggable<Logger::Id::wasm>, public std::enable_share
Context* vm_context() const { return vm_context_.get(); }
Stats::StatNameSetSharedPtr stat_name_set() const { return stat_name_set_; }
Context* getRootContext(absl::string_view root_id) { return root_contexts_[root_id].get(); }
Context* getOrCreateRootContext(const PluginSharedPtr& plugin);
Context* getContext(uint32_t id) {
auto it = contexts_.find(id);
if (it != contexts_.end())
Expand Down