From 8f4c5d5d1dbb772a29f059645f0f03a4556c1dad Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Sat, 3 Nov 2018 22:34:05 +0800 Subject: [PATCH] Change HostClient.pendingRequest to an int32 atomic.AddUint64 needs a 64bit aligned address on x86, int32 is more than enough and keeps the code more readable. Fixes #451 --- client.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client.go b/client.go index 866254a2a6..a9b83fb0da 100644 --- a/client.go +++ b/client.go @@ -611,7 +611,7 @@ type HostClient struct { readerPool sync.Pool writerPool sync.Pool - pendingRequests uint64 + pendingRequests int32 connsCleanerRun bool } @@ -1021,7 +1021,7 @@ func (c *HostClient) Do(req *Request, resp *Response) error { } attempts := 0 - atomic.AddUint64(&c.pendingRequests, 1) + atomic.AddInt32(&c.pendingRequests, 1) for { retry, err = c.do(req, resp) if err == nil || !retry { @@ -1045,7 +1045,7 @@ func (c *HostClient) Do(req *Request, resp *Response) error { break } } - atomic.AddUint64(&c.pendingRequests, ^uint64(0)) + atomic.AddInt32(&c.pendingRequests, -1) if err == io.EOF { err = ErrConnectionClosed @@ -1059,7 +1059,7 @@ func (c *HostClient) Do(req *Request, resp *Response) error { // This function may be used for balancing load among multiple HostClient // instances. func (c *HostClient) PendingRequests() int { - return int(atomic.LoadUint64(&c.pendingRequests)) + return int(atomic.LoadInt32(&c.pendingRequests)) } func isIdempotent(req *Request) bool {