From 16d645c6b3955dbffae07dd5eb428d28c71ad658 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 9 Feb 2023 20:41:45 +0100 Subject: [PATCH] Move atomicError type into internal package Move atomicError type into internal package --- agent.go | 3 ++- internal/atomic/atomic.go | 20 ++++++++++++++++++++ util.go | 12 ------------ 3 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 internal/atomic/atomic.go diff --git a/agent.go b/agent.go index 66ae3f7..b1017d3 100644 --- a/agent.go +++ b/agent.go @@ -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{} diff --git a/internal/atomic/atomic.go b/internal/atomic/atomic.go new file mode 100644 index 0000000..10730a0 --- /dev/null +++ b/internal/atomic/atomic.go @@ -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 +} diff --git a/util.go b/util.go index a2ccb8b..ec18691 100644 --- a/util.go +++ b/util.go @@ -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 {