Skip to content

Commit

Permalink
Fix race.
Browse files Browse the repository at this point in the history
Signed-off-by: Nuno Cruces <[email protected]>
  • Loading branch information
ncruces committed Jan 17, 2025
1 parent 70425b8 commit 451d3fb
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,29 +151,31 @@ func NewRuntime(ctx context.Context) Runtime {
// NewRuntimeWithConfig returns a runtime with the given configuration.
func NewRuntimeWithConfig(ctx context.Context, rConfig RuntimeConfig) Runtime {
config := rConfig.(*runtimeConfig)
if config.engineKind == engineKindAuto {
configKind := config.engineKind
configEngine := config.newEngine
if configKind == engineKindAuto {
if platform.CompilerSupports(config.enabledFeatures) {
config.engineKind = engineKindCompiler
configKind = engineKindCompiler
} else {
config.engineKind = engineKindInterpreter
configKind = engineKindInterpreter
}
}
if config.newEngine == nil {
if config.engineKind == engineKindCompiler {
config.newEngine = wazevo.NewEngine
if configEngine == nil {
if configKind == engineKindCompiler {
configEngine = wazevo.NewEngine
} else {
config.newEngine = interpreter.NewEngine
configEngine = interpreter.NewEngine
}
}
var engine wasm.Engine
var cacheImpl *cache
if c := config.cache; c != nil {
// If the Cache is configured, we share the engine.
cacheImpl = c.(*cache)
engine = cacheImpl.initEngine(config.engineKind, config.newEngine, ctx, config.enabledFeatures)
engine = cacheImpl.initEngine(configKind, configEngine, ctx, config.enabledFeatures)
} else {
// Otherwise, we create a new engine.
engine = config.newEngine(ctx, config.enabledFeatures, nil)
engine = configEngine(ctx, config.enabledFeatures, nil)
}
store := wasm.NewStore(config.enabledFeatures, engine)
return &runtime{
Expand Down

0 comments on commit 451d3fb

Please sign in to comment.