Skip to content

Commit

Permalink
Merge pull request hashicorp#233 from hashicorp/b-fix-alignment-on-32bit
Browse files Browse the repository at this point in the history
Put 64bit atomics at the top of structs
  • Loading branch information
schmichael authored Aug 7, 2017
2 parents 44f9cae + 9fac96c commit ac70407
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 6 additions & 4 deletions observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ type FilterFn func(o *Observation) bool

// Observer describes what to do with a given observation.
type Observer struct {
// numObserved and numDropped are performance counters for this observer.
// 64 bit types must be 64 bit aligned to use with atomic operations on
// 32 bit platforms, so keep them at the top of the struct.
numObserved uint64
numDropped uint64

// channel receives observations.
channel chan Observation

Expand All @@ -42,10 +48,6 @@ type Observer struct {

// id is the ID of this observer in the Raft map.
id uint64

// numObserved and numDropped are performance counters for this observer.
numObserved uint64
numDropped uint64
}

// NewObserver creates a new observer that can be registered
Expand Down
4 changes: 4 additions & 0 deletions state.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ func (s RaftState) String() string {
// and provides an interface to set/get the variables in a
// thread safe manner.
type raftState struct {
// currentTerm commitIndex, lastApplied, must be kept at the top of
// the struct so they're 64 bit aligned which is a requirement for
// atomic ops on 32 bit platforms.

// The current term, cache of StableStore
currentTerm uint64

Expand Down

0 comments on commit ac70407

Please sign in to comment.