Skip to content

Commit 0382d1e

Browse files
committed
Merge pull request #257 from go-redis/fix/use-uint32
Use uint32 because uint64 requires manual alignment on 386 arch. Fixes #256.
2 parents 298fdec + e750d2b commit 0382d1e

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

pool.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ var (
1717

1818
// PoolStats contains pool state information and accumulated stats.
1919
type PoolStats struct {
20-
Requests uint64 // number of times a connection was requested by the pool
21-
Waits uint64 // number of times our pool had to wait for a connection
22-
Timeouts uint64 // number of times a wait timeout occurred
20+
Requests uint32 // number of times a connection was requested by the pool
21+
Waits uint32 // number of times our pool had to wait for a connection
22+
Timeouts uint32 // number of times a wait timeout occurred
2323

24-
TotalConns uint64 // the number of total connections in the pool
25-
FreeConns uint64 // the number of free connections in the pool
24+
TotalConns uint32 // the number of total connections in the pool
25+
FreeConns uint32 // the number of free connections in the pool
2626
}
2727

2828
type pool interface {
@@ -237,7 +237,7 @@ func (p *connPool) Get() (cn *conn, isNew bool, err error) {
237237
return
238238
}
239239

240-
atomic.AddUint64(&p.stats.Requests, 1)
240+
atomic.AddUint32(&p.stats.Requests, 1)
241241

242242
// Fetch first non-idle connection, if available.
243243
if cn = p.First(); cn != nil {
@@ -257,12 +257,12 @@ func (p *connPool) Get() (cn *conn, isNew bool, err error) {
257257
}
258258

259259
// Otherwise, wait for the available connection.
260-
atomic.AddUint64(&p.stats.Waits, 1)
260+
atomic.AddUint32(&p.stats.Waits, 1)
261261
if cn = p.wait(); cn != nil {
262262
return
263263
}
264264

265-
atomic.AddUint64(&p.stats.Timeouts, 1)
265+
atomic.AddUint32(&p.stats.Timeouts, 1)
266266
err = errPoolTimeout
267267
return
268268
}
@@ -315,11 +315,11 @@ func (p *connPool) FreeLen() int {
315315

316316
func (p *connPool) Stats() *PoolStats {
317317
stats := p.stats
318-
stats.Requests = atomic.LoadUint64(&p.stats.Requests)
319-
stats.Waits = atomic.LoadUint64(&p.stats.Waits)
320-
stats.Timeouts = atomic.LoadUint64(&p.stats.Timeouts)
321-
stats.TotalConns = uint64(p.Len())
322-
stats.FreeConns = uint64(p.FreeLen())
318+
stats.Requests = atomic.LoadUint32(&p.stats.Requests)
319+
stats.Waits = atomic.LoadUint32(&p.stats.Waits)
320+
stats.Timeouts = atomic.LoadUint32(&p.stats.Timeouts)
321+
stats.TotalConns = uint32(p.Len())
322+
stats.FreeConns = uint32(p.FreeLen())
323323
return &stats
324324
}
325325

0 commit comments

Comments
 (0)