all: use atomic.Pointer

Also add some missing docs.

Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
Maisem Ali
2022-08-03 21:31:40 -07:00
committed by Maisem Ali
parent 5381437664
commit 9bb5a038e5
9 changed files with 21 additions and 24 deletions

View File

@@ -24,8 +24,8 @@ func init() {
} else if n > 10000 {
n = 10000
}
fl, ok := fwdLogAtomic.Load().(*fwdLog)
if !ok || n != len(fl.ent) {
fl := fwdLogAtomic.Load()
if fl == nil || n != len(fl.ent) {
fl = &fwdLog{ent: make([]fwdLogEntry, n)}
fwdLogAtomic.Store(fl)
}
@@ -33,7 +33,7 @@ func init() {
}))
}
var fwdLogAtomic atomic.Value // of *fwdLog
var fwdLogAtomic atomic.Pointer[fwdLog]
type fwdLog struct {
mu sync.Mutex

View File

@@ -688,7 +688,7 @@ func (f *forwarder) forwardWithDestChan(ctx context.Context, query packet, respo
}
}
if fl, ok := fwdLogAtomic.Load().(*fwdLog); ok {
if fl := fwdLogAtomic.Load(); fl != nil {
fl.addName(string(domain))
}