summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2016-12-16 00:27:18 +0000
committerBrad Fitzpatrick <bradfitz@golang.org>2016-12-16 00:27:18 +0000
commitd092608c065831f1984ac9d332ca5b2c95a11f57 (patch)
tree6bf4dfffada59b6d767553b9a4fbd525a6a5a8be
parenta6b377e3400b08991b80d6805d627f347f983866 (diff)
downloadgolang-groupcache-d092608c065831f1984ac9d332ca5b2c95a11f57.tar.gz
Align Group.Stats properly for 32-bit platforms.
Fixes golang/go#18334
-rw-r--r--groupcache.go2
-rw-r--r--groupcache_test.go9
2 files changed, 11 insertions, 0 deletions
diff --git a/groupcache.go b/groupcache.go
index c227237..316ca49 100644
--- a/groupcache.go
+++ b/groupcache.go
@@ -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
}
diff --git a/groupcache_test.go b/groupcache_test.go
index 3a4ecc2..ea05cac 100644
--- a/groupcache_test.go
+++ b/groupcache_test.go
@@ -27,6 +27,7 @@ import (
"sync"
"testing"
"time"
+ "unsafe"
"github.com/golang/protobuf/proto"
@@ -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.