Align Group.Stats properly for 32-bit platforms.
Fixes golang/go#18334
diff --git a/groupcache.go b/groupcache.go
index c227237..316ca49 100644
--- a/groupcache.go
+++ b/groupcache.go
@@ -166,6 +166,8 @@
// 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 @@
"sync"
"testing"
"time"
+ "unsafe"
"github.com/golang/protobuf/proto"
@@ -443,5 +444,13 @@
}
}
+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.