From 773147ef7118a2d09966f6351d6da5ff07f6868c Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Fri, 8 Nov 2019 00:34:04 +0100 Subject: [PATCH] fix: properly align atomic counters --- interp/interp.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/interp/interp.go b/interp/interp.go index bb35a106a..8fe3de84b 100644 --- a/interp/interp.go +++ b/interp/interp.go @@ -53,11 +53,14 @@ type receiver struct { // frame contains values for the current execution level (a function context) type frame struct { + // id is an atomic counter used for cancellation, only access + // via newFrame/runid/setrunid/clone. + // Located at start of struct to ensure proper aligment. + id uint64 + anc *frame // ancestor frame (global space) data []reflect.Value // values - id uint64 // for cancellation, only access via newFrame/runid/setrunid/clone. - mutex sync.RWMutex deferred [][]reflect.Value // defer stack recovered interface{} // to handle panic recover @@ -108,6 +111,12 @@ type opt struct { // Interpreter contains global resources and state type Interpreter struct { + // id is an atomic counter counter used for run cancellation, + // only accessed via runid/stop + // Located at start of struct to ensure proper alignment on 32 bit + // architectures. + id uint64 + Name string // program name opt // user settable options @@ -117,8 +126,6 @@ type Interpreter struct { binPkg Exports // binary packages used in interpreter, indexed by path rdir map[string]bool // for src import cycle detection - id uint64 // for cancellation, only accessed via runid/stop - mutex sync.RWMutex frame *frame // program data storage during execution universe *scope // interpreter global level scope