Skip to content

Commit 10e98b1

Browse files
committed
fix int64 alignment for atomic operations
1 parent 2cf8d45 commit 10e98b1

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

internal/pool/pool.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ type ConnPool struct {
9191
poolSize int
9292
idleConnsLen int
9393

94-
stats Stats
94+
stats Stats
95+
waitDurationNs atomic.Int64
9596

9697
_closed uint32 // atomic
9798
}
@@ -318,7 +319,7 @@ func (p *ConnPool) waitTurn(ctx context.Context) error {
318319
timers.Put(timer)
319320
return ctx.Err()
320321
case p.queue <- struct{}{}:
321-
atomic.AddInt64(&p.stats.WaitDurationNs, time.Since(start).Nanoseconds())
322+
p.waitDurationNs.Add(time.Since(start).Nanoseconds())
322323
atomic.AddUint32(&p.stats.WaitCount, 1)
323324
if !timer.Stop() {
324325
<-timer.C
@@ -450,7 +451,7 @@ func (p *ConnPool) Stats() *Stats {
450451
Misses: atomic.LoadUint32(&p.stats.Misses),
451452
Timeouts: atomic.LoadUint32(&p.stats.Timeouts),
452453
WaitCount: atomic.LoadUint32(&p.stats.WaitCount),
453-
WaitDurationNs: atomic.LoadInt64(&p.stats.WaitDurationNs),
454+
WaitDurationNs: p.waitDurationNs.Load(),
454455

455456
TotalConns: uint32(p.Len()),
456457
IdleConns: uint32(p.IdleLen()),

0 commit comments

Comments
 (0)