Skip to content

Commit

Permalink
Change HostClient.pendingRequest to an int32
Browse files Browse the repository at this point in the history
atomic.AddUint64 needs a 64bit aligned address on x86, int32 is more
than enough and keeps the code more readable.

Fixes #451
  • Loading branch information
erikdubbelboer committed Nov 3, 2018
1 parent 6b0a1c5 commit 8f4c5d5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions client.go
Expand Up @@ -611,7 +611,7 @@ type HostClient struct {
readerPool sync.Pool
writerPool sync.Pool

pendingRequests uint64
pendingRequests int32

connsCleanerRun bool
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 8f4c5d5

Please sign in to comment.