From c075349a33119b243dc0b3efc94072d7bf1bc201 Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Fri, 4 Aug 2017 10:14:16 -0700 Subject: [PATCH] Use int32 for atomic ops to avoid alignment issues From https://golang.org/pkg/sync/atomic/#pkg-note-BUG : On both ARM and x86-32, it is the caller's responsibility to arrange for 64-bit alignment of 64-bit words accessed atomically. The first word in a global variable or in an allocated struct or slice can be relied upon to be 64-bit aligned. --- command/agent/consul/client.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/command/agent/consul/client.go b/command/agent/consul/client.go index a1710250c..0900c82b3 100644 --- a/command/agent/consul/client.go +++ b/command/agent/consul/client.go @@ -119,7 +119,7 @@ type ServiceClient struct { // seen is 1 if Consul has ever been seen; otherise 0. Accessed with // atomics. - seen int64 + seen int32 } // NewServiceClient creates a new Consul ServiceClient from an existing Consul API @@ -150,13 +150,13 @@ const seen = 1 // markSeen marks Consul as having been seen (meaning at least one operation // has succeeded). func (c *ServiceClient) markSeen() { - atomic.StoreInt64(&c.seen, seen) + atomic.StoreInt32(&c.seen, seen) } // hasSeen returns true if any Consul operation has ever succeeded. Useful to // squelch errors if Consul isn't running. func (c *ServiceClient) hasSeen() bool { - return atomic.LoadInt64(&c.seen) == seen + return atomic.LoadInt32(&c.seen) == seen } // Run the Consul main loop which retries operations against Consul. It should