switch to new sync/atomic helpers in go1.19 (#728)

These new helpers make the code a lot cleaner. I confirmed that the
simple helpers like `atomic.Int64` don't add any extra overhead as they
get inlined by the compiler. `atomic.Pointer` adds an extra method call
as it no longer gets inlined, but we aren't using these on the hot path
so it is probably okay.
This commit is contained in:
Wade Simmons 2022-10-31 13:37:41 -04:00 committed by GitHub
parent a800a48857
commit 9af242dc47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 126 additions and 145 deletions

View file

@ -67,7 +67,7 @@ type Interface struct {
routines int
caPool *cert.NebulaCAPool
disconnectInvalid bool
closed int32
closed atomic.Bool
relayManager *relayManager
sendRecvErrorConfig sendRecvErrorConfig
@ -253,7 +253,7 @@ func (f *Interface) listenIn(reader io.ReadWriteCloser, i int) {
for {
n, err := reader.Read(packet)
if err != nil {
if errors.Is(err, os.ErrClosed) && atomic.LoadInt32(&f.closed) != 0 {
if errors.Is(err, os.ErrClosed) && f.closed.Load() {
return
}
@ -391,7 +391,7 @@ func (f *Interface) emitStats(ctx context.Context, i time.Duration) {
}
func (f *Interface) Close() error {
atomic.StoreInt32(&f.closed, 1)
f.closed.Store(true)
// Release the tun device
return f.inside.Close()