Move atomicError type into internal package

Move atomicError type into internal package
This commit is contained in:
Steffen Vogel
2023-02-10 22:48:36 +01:00
parent 583ad442c1
commit 16d645c6b3
3 changed files with 22 additions and 13 deletions
+2 -1
View File
@@ -11,6 +11,7 @@ import (
"sync/atomic"
"time"
atomicx "github.com/pion/ice/v2/internal/atomic"
"github.com/pion/logging"
"github.com/pion/mdns"
"github.com/pion/stun"
@@ -114,7 +115,7 @@ type Agent struct {
// State for closing
done chan struct{}
taskLoopDone chan struct{}
err atomicError
err atomicx.Error
gatherCandidateCancel func()
gatherCandidateDone chan struct{}
+20
View File
@@ -0,0 +1,20 @@
// Package atomic contains custom atomic types
package atomic
import "sync/atomic"
// Error is an atomic error
type Error struct {
v atomic.Value
}
// Store updates the value of the atomic variable
func (a *Error) Store(err error) {
a.v.Store(struct{ error }{err})
}
// Load retrieves the current value of the atomic variable
func (a *Error) Load() error {
err, _ := a.v.Load().(struct{ error })
return err.error
}
-12
View File
@@ -3,7 +3,6 @@ package ice
import (
"fmt"
"net"
"sync/atomic"
"time"
"github.com/pion/logging"
@@ -11,17 +10,6 @@ import (
"github.com/pion/transport/v2"
)
type atomicError struct{ v atomic.Value }
func (a *atomicError) Store(err error) {
a.v.Store(struct{ error }{err})
}
func (a *atomicError) Load() error {
err, _ := a.v.Load().(struct{ error })
return err.error
}
// The conditions of invalidation written below are defined in
// https://tools.ietf.org/html/rfc8445#section-5.1.1.1
func isSupportedIPv6(ip net.IP) bool {