@@ -19,7 +19,7 @@ type ConnPool struct {
1919 host string
2020 nrShards int
2121 msbIgnore uint8
22- conns []atomic.Value
22+ conns []atomic.Pointer [ Conn ]
2323 connClosedCh chan int // notification channel for when connection is closed
2424 connObs ConnObserver
2525}
@@ -99,13 +99,11 @@ func (p *ConnPool) storeConn(conn *Conn) {
9999}
100100
101101func (p * ConnPool ) loadConn (shard int ) * Conn {
102- conn , _ := p .conns [shard ].Load ().(* Conn )
103- return conn
102+ return p .conns [shard ].Load ()
104103}
105104
106105func (p * ConnPool ) clearConn (shard int ) bool {
107- conn , _ := p .conns [shard ].Swap ((* Conn )(nil )).(* Conn )
108- return conn != nil
106+ return p .conns [shard ].Swap (nil ) != nil
109107}
110108
111109func (p * ConnPool ) Close () {
@@ -115,7 +113,7 @@ func (p *ConnPool) Close() {
115113// closeAll is called by PoolRefiller.
116114func (p * ConnPool ) closeAll () {
117115 for i := range p .conns {
118- if conn , ok := p .conns [i ].Swap (( * Conn )( nil )).( * Conn ); ok {
116+ if conn := p .conns [i ].Swap (nil ); conn != nil {
119117 conn .Close ()
120118 }
121119 }
@@ -168,7 +166,7 @@ func (r *PoolRefiller) init(ctx context.Context, host string) error {
168166 host : host ,
169167 nrShards : int (ss .NrShards ),
170168 msbIgnore : ss .MsbIgnore ,
171- conns : make ([]atomic.Value , int (ss .NrShards )),
169+ conns : make ([]atomic.Pointer [ Conn ] , int (ss .NrShards )),
172170 connClosedCh : make (chan int , int (ss .NrShards )+ 1 ),
173171 connObs : r .cfg .ConnObserver ,
174172 }
0 commit comments