utils.AtomicFlag -> atomic.Bool (#466)

* Replacing hand rolled ion-sfu atomic with uber/atomic

* Remove another hand rolled atomic

* utils.AtomicFlag -> atomic.Bool
This commit is contained in:
Raja Subramanian
2022-02-25 12:19:49 +05:30
committed by GitHub
parent 0170cc1cb6
commit 778d1aa141
14 changed files with 83 additions and 85 deletions
+4 -4
View File
@@ -7,8 +7,8 @@ import (
"github.com/livekit/livekit-server/pkg/sfu/buffer"
"github.com/livekit/protocol/livekit"
"github.com/livekit/protocol/logger"
"github.com/livekit/protocol/utils"
"github.com/pion/webrtc/v3"
"go.uber.org/atomic"
)
const (
@@ -43,7 +43,7 @@ type ConnectionStats struct {
qualityWindows map[uint32]*qualityWindow
done chan struct{}
isClosed utils.AtomicFlag
isClosed atomic.Bool
}
func NewConnectionStats(params ConnectionStatsParams) *ConnectionStats {
@@ -60,7 +60,7 @@ func (cs *ConnectionStats) Start() {
}
func (cs *ConnectionStats) Close() {
if !cs.isClosed.TrySet(true) {
if cs.isClosed.Swap(true) {
return
}
@@ -79,7 +79,7 @@ func (cs *ConnectionStats) GetScore() float32 {
}
func (cs *ConnectionStats) UpdateWindow(ssrc uint32, extHighestSeqNum uint32, packetsLost uint32, rtt uint32, jitter uint32) {
if cs.isClosed.Get() {
if cs.isClosed.Load() {
return
}
+5 -5
View File
@@ -9,10 +9,10 @@ import (
"github.com/livekit/protocol/livekit"
"github.com/livekit/protocol/logger"
"github.com/livekit/protocol/utils"
"github.com/pion/interceptor/pkg/cc"
"github.com/pion/rtcp"
"github.com/pion/webrtc/v3"
"go.uber.org/atomic"
"github.com/livekit/livekit-server/pkg/config"
)
@@ -153,7 +153,7 @@ type StreamAllocator struct {
eventChMu sync.RWMutex
eventCh chan Event
isStopped utils.AtomicFlag
isStopped atomic.Bool
}
func NewStreamAllocator(params StreamAllocatorParams) *StreamAllocator {
@@ -182,7 +182,7 @@ func (s *StreamAllocator) Start() {
func (s *StreamAllocator) Stop() {
s.eventChMu.Lock()
if !s.isStopped.TrySet(true) {
if s.isStopped.Swap(true) {
s.eventChMu.Unlock()
return
}
@@ -320,7 +320,7 @@ func (s *StreamAllocator) onProbeClusterDone(info ProbeClusterInfo) {
func (s *StreamAllocator) postEvent(event Event) {
s.eventChMu.RLock()
if s.isStopped.Get() {
if s.isStopped.Load() {
s.eventChMu.RUnlock()
return
}
@@ -340,7 +340,7 @@ func (s *StreamAllocator) ping() {
for {
<-ticker.C
if s.isStopped.Get() {
if s.isStopped.Load() {
return
}
+3 -5
View File
@@ -5,8 +5,6 @@ import (
"time"
"go.uber.org/atomic"
"github.com/livekit/protocol/utils"
)
type StreamStatus int32
@@ -54,7 +52,7 @@ type StreamTracker struct {
// only access by the same goroutine as Observe
lastSN uint16
isStopped utils.AtomicFlag
isStopped atomic.Bool
}
func NewStreamTracker(samplesRequired uint32, cyclesRequired uint64, cycleDuration time.Duration) *StreamTracker {
@@ -110,7 +108,7 @@ func (s *StreamTracker) Start() {
}
func (s *StreamTracker) Stop() {
if !s.isStopped.TrySet(true) {
if s.isStopped.Swap(true) {
return
}
@@ -119,7 +117,7 @@ func (s *StreamTracker) Stop() {
}
func (s *StreamTracker) Reset() {
if s.isStopped.Get() {
if s.isStopped.Load() {
return
}