Skip to content

Commit

Permalink
Align Group.Stats properly for 32-bit platforms.
Browse files Browse the repository at this point in the history
  • Loading branch information
bradfitz committed Dec 16, 2016
1 parent a6b377e commit d092608
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions groupcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ type Group struct {
// concurrent callers.
loadGroup flightGroup

_ int32 // force Stats to be 8-byte aligned on 32-bit platforms

// Stats are statistics on the group.
Stats Stats
}
Expand Down
9 changes: 9 additions & 0 deletions groupcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"sync"
"testing"
"time"
"unsafe"

"github.com/golang/protobuf/proto"

Expand Down Expand Up @@ -443,5 +444,13 @@ func TestNoDedup(t *testing.T) {
}
}

func TestGroupStatsAlignment(t *testing.T) {
var g Group
off := unsafe.Offsetof(g.Stats)
if off%8 != 0 {
t.Fatal("Stats structure is not 8-byte aligned.")
}
}

// TODO(bradfitz): port the Google-internal full integration test into here,
// using HTTP requests instead of our RPC system.

0 comments on commit d092608

Please sign in to comment.