wasm: move ModuleInstance.Closed to the top (#1321)
ModuleInstance.Closed is an atomic variable meant to be loaded and swapped with sync/atomic. Closed, being a 64 bit integer, requires 64 bit alignment. The simplest way we can get alignment is to place these atomic fields at the top of their struct. Closed can be moved to a more logical place once support for Go 1.18 is dropped and its type changed to atomic.Uint64. Signed-off-by: Tristan Willy <tristan.willy@gmail.com>
This commit is contained in:
@@ -58,6 +58,17 @@ type (
|
||||
//
|
||||
// This implements api.Module.
|
||||
ModuleInstance struct {
|
||||
// Closed is used both to guard moduleEngine.CloseWithExitCode and to store the exit code.
|
||||
//
|
||||
// The update value is closedType + exitCode << 32. This ensures an exit code of zero isn't mistaken for never closed.
|
||||
//
|
||||
// Note: Exclusively reading and updating this with atomics guarantees cross-goroutine observations.
|
||||
// See /RATIONALE.md
|
||||
//
|
||||
// TODO: Retype this to atomic.Unit64 when Go 1.18 is no longer supported. Until then, keep Closed at the top of
|
||||
// this struct. See PR #1299 for an implementation and discussion.
|
||||
Closed uint64
|
||||
|
||||
ModuleName string
|
||||
Exports map[string]*Export
|
||||
Globals []*GlobalInstance
|
||||
@@ -94,14 +105,6 @@ type (
|
||||
// security implications.
|
||||
Sys *internalsys.Context
|
||||
|
||||
// closed is the pointer used both to guard moduleEngine.CloseWithExitCode and to store the exit code.
|
||||
//
|
||||
// The update value is closedType + exitCode << 32. This ensures an exit code of zero isn't mistaken for never closed.
|
||||
//
|
||||
// Note: Exclusively reading and updating this with atomics guarantees cross-goroutine observations.
|
||||
// See /RATIONALE.md
|
||||
Closed uint64
|
||||
|
||||
// CodeCloser is non-nil when the code should be closed after this module.
|
||||
CodeCloser api.Closer
|
||||
|
||||
|
||||
Reference in New Issue
Block a user