diff options
author | Ian Lance Taylor <iant@golang.org> | 2022-11-16 14:19:47 -0800 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2022-11-17 00:13:03 +0000 |
commit | b7662047aedc5f2c512911eb59d514ce75b16e18 (patch) | |
tree | 17d533d4eb097ce68ec3ab97003741b12d7034d1 /src/net/dnsclient_unix_test.go | |
parent | a2d8157a7ecc8c7a91c93182ae4778aef505677e (diff) | |
download | go-git-b7662047aedc5f2c512911eb59d514ce75b16e18.tar.gz |
net: change resolverConfig.dnsConfig to an atomic.Pointer
We were using a RWMutex RLock around a single memory load,
which is not a good use of a RWMutex--it introduces extra work
for the RLock but contention around a single memory load is unlikely.
And, the tryUpdate method was not acquiring the mutex anyhow.
The new atomic.Pointer type is type-safe and easy to use correctly
for a simple use-case like this.
Change-Id: Ib3859c03414c44d2e897f6d15c92c8e4b5c81a11
Reviewed-on: https://go-review.googlesource.com/c/go/+/451416
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/net/dnsclient_unix_test.go')
-rw-r--r-- | src/net/dnsclient_unix_test.go | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/src/net/dnsclient_unix_test.go b/src/net/dnsclient_unix_test.go index c2a85db6de..2a15845ea1 100644 --- a/src/net/dnsclient_unix_test.go +++ b/src/net/dnsclient_unix_test.go @@ -280,9 +280,7 @@ func (conf *resolvConfTest) forceUpdate(name string, lastChecked time.Time) erro } func (conf *resolvConfTest) forceUpdateConf(c *dnsConfig, lastChecked time.Time) bool { - conf.mu.Lock() - conf.dnsConfig = c - conf.mu.Unlock() + conf.dnsConfig.Store(c) for i := 0; i < 5; i++ { if conf.tryAcquireSema() { conf.lastChecked = lastChecked @@ -294,10 +292,7 @@ func (conf *resolvConfTest) forceUpdateConf(c *dnsConfig, lastChecked time.Time) } func (conf *resolvConfTest) servers() []string { - conf.mu.RLock() - servers := conf.dnsConfig.servers - conf.mu.RUnlock() - return servers + return conf.dnsConfig.Load().servers } func (conf *resolvConfTest) teardown() error { @@ -1445,9 +1440,7 @@ func TestDNSGoroutineRace(t *testing.T) { func lookupWithFake(fake fakeDNSServer, name string, typ dnsmessage.Type) error { r := Resolver{PreferGo: true, Dial: fake.DialContext} - resolvConf.mu.RLock() - conf := resolvConf.dnsConfig - resolvConf.mu.RUnlock() + conf := resolvConf.dnsConfig.Load() ctx, cancel := context.WithCancel(context.Background()) defer cancel() |