Skip to content

Commit

Permalink
review feedback; improve docs
Browse files Browse the repository at this point in the history
Signed-off-by: Vicent Marti <[email protected]>
  • Loading branch information
vmg committed Feb 13, 2025
1 parent d1e244d commit 092a0a4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
2 changes: 1 addition & 1 deletion go/pools/smartconnpool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (pool *ConnPool[C]) open() {

// The expire worker takes care of removing from the waiter list any clients whose
// context has been cancelled.
pool.runWorker(pool.close, 100*time.Millisecond, func(now time.Time) bool {
pool.runWorker(pool.close, 100*time.Millisecond, func(_ time.Time) bool {
maybeStarving := pool.wait.expire(false)

// Do not allow connections to starve; if there's waiters in the queue
Expand Down
25 changes: 3 additions & 22 deletions go/pools/smartconnpool/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import (
// connStack is a lock-free stack for Connection objects. It is safe to
// use from several goroutines.
type connStack[C Connection] struct {
// top is a pointer to the top node on the stack and to an increasing
// counter of pop operations, to prevent A-B-A races.
// See: https://en.wikipedia.org/wiki/ABA_problem
top atomic2.PointerAndUint64[Pooled[C]]
}

Expand Down Expand Up @@ -58,25 +61,3 @@ func (s *connStack[C]) Peek() *Pooled[C] {
top, _ := s.top.Load()
return top
}

func (s *connStack[C]) PopAll(out []*Pooled[C]) []*Pooled[C] {
var oldHead *Pooled[C]

for {
var popCount uint64
oldHead, popCount = s.top.Load()
if oldHead == nil {
return out
}
if s.top.CompareAndSwap(oldHead, popCount, nil, popCount+1) {
break
}
runtime.Gosched()
}

for oldHead != nil {
out = append(out, oldHead)
oldHead = oldHead.next.Load()
}
return out
}

0 comments on commit 092a0a4

Please sign in to comment.