Skip to content

Commit

Permalink
fix: properly align atomic counters
Browse files Browse the repository at this point in the history
  • Loading branch information
mvertes authored and traefiker committed Nov 7, 2019
1 parent a6eceba commit 773147e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions interp/interp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 773147e

Please sign in to comment.