Skip to content

Commit

Permalink
Move atomic members to beginning of structs to guarantee 64bit alignm…
Browse files Browse the repository at this point in the history
…ent.
  • Loading branch information
kozlovic committed Nov 19, 2015
1 parent 477cce5 commit 21ed327
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions nats.go
Expand Up @@ -135,13 +135,13 @@ const (
// A Conn represents a bare connection to a nats-server. It will send and receive
// []byte payloads.
type Conn struct {
Statistics

// Keep ssid as first element of the struct to guarantee
// 64bit alignment. atomic.* functions crash on 32bit machines if operand is not
// aligned at 64bit. See https://github.com/golang/go/issues/599
ssid int64
// Keep all members for which we use atomic at the beginning of the
// struct and make sure they are all 64bits (or use padding if necessary).
// atomic.* functions crash on 32bit machines if operand is not aligned
// at 64bit. See https://github.com/golang/go/issues/599
ssid int64

Statistics
mu sync.Mutex
Opts Options
wg sync.WaitGroup
Expand All @@ -165,6 +165,12 @@ type Conn struct {

// A Subscription represents interest in a given subject.
type Subscription struct {
// Keep all members for which we use atomic at the beginning of the
// struct and make sure they are all 64bits (or use padding if necessary).
// atomic.* functions crash on 32bit machines if operand is not aligned
// at 64bit. See https://github.com/golang/go/issues/599
delivered uint64

mu sync.Mutex
sid int64

Expand All @@ -177,15 +183,14 @@ type Subscription struct {
// only be processed by one member of the group.
Queue string

msgs uint64
delivered uint64
bytes uint64
max uint64
conn *Conn
closed bool
mcb MsgHandler
mch chan *Msg
sc bool
msgs uint64
bytes uint64
max uint64
conn *Conn
closed bool
mcb MsgHandler
mch chan *Msg
sc bool
}

// Msg is a structure used by Subscribers and PublishMsg().
Expand Down

0 comments on commit 21ed327

Please sign in to comment.