Skip to content

Commit 85c47b3

Browse files
authored
priority: use new-style atomic APIs (#8558)
Use new-style atomic APIs instead of the old ones in the `ignoreResolveNowClientConn` type. The changes made in this PR improve the code in the following ways: * Ergonomics: Method-based API vs function-based, no pointer management needed * Safety: Type safety prevents mixing atomic/non-atomic operations, eliminates pointer errors * Clarity: The `atomic.Uint32` type makes atomic intent explicit from declaration RELEASE NOTES: none
1 parent 5780703 commit 85c47b3

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

internal/xds/balancer/priority/ignore_resolve_now.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,21 @@ import (
2929
// ResolveNow() method to ignore those calls if the ignoreResolveNow bit is set.
3030
type ignoreResolveNowClientConn struct {
3131
balancer.ClientConn
32-
ignoreResolveNow *uint32
32+
ignoreResolveNow atomic.Bool
3333
}
3434

3535
func newIgnoreResolveNowClientConn(cc balancer.ClientConn, ignore bool) *ignoreResolveNowClientConn {
36-
ret := &ignoreResolveNowClientConn{
37-
ClientConn: cc,
38-
ignoreResolveNow: new(uint32),
39-
}
36+
ret := &ignoreResolveNowClientConn{ClientConn: cc}
4037
ret.updateIgnoreResolveNow(ignore)
4138
return ret
4239
}
4340

4441
func (i *ignoreResolveNowClientConn) updateIgnoreResolveNow(b bool) {
45-
if b {
46-
atomic.StoreUint32(i.ignoreResolveNow, 1)
47-
return
48-
}
49-
atomic.StoreUint32(i.ignoreResolveNow, 0)
50-
42+
i.ignoreResolveNow.Store(b)
5143
}
5244

53-
func (i ignoreResolveNowClientConn) ResolveNow(o resolver.ResolveNowOptions) {
54-
if atomic.LoadUint32(i.ignoreResolveNow) != 0 {
45+
func (i *ignoreResolveNowClientConn) ResolveNow(o resolver.ResolveNowOptions) {
46+
if i.ignoreResolveNow.Load() {
5547
return
5648
}
5749
i.ClientConn.ResolveNow(o)

0 commit comments

Comments
 (0)