Replacing hand rolled ion-sfu atomic with uber/atomic (#465)

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

* Remove another hand rolled atomic
This commit is contained in:
Raja Subramanian
2022-02-25 11:57:09 +05:30
committed by GitHub
parent 2959eebca8
commit 5a4181b581
11 changed files with 90 additions and 150 deletions
+9 -9
View File
@@ -4,7 +4,6 @@ import (
"io"
"runtime"
"sync"
"sync/atomic"
"time"
"github.com/go-logr/logr"
@@ -13,6 +12,7 @@ import (
"github.com/pion/rtcp"
"github.com/pion/webrtc/v3"
"github.com/rs/zerolog/log"
"go.uber.org/atomic"
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/pkg/sfu/buffer"
@@ -58,7 +58,7 @@ type WebRTCReceiver struct {
isSimulcast bool
onCloseHandler func()
closeOnce sync.Once
closed atomicBool
closed atomic.Bool
useTrackers bool
rtcpCh chan []rtcp.Packet
@@ -239,7 +239,7 @@ func (w *WebRTCReceiver) Kind() webrtc.RTPCodecType {
}
func (w *WebRTCReceiver) AddUpTrack(track *webrtc.TrackRemote, buff *buffer.Buffer) {
if w.closed.get() {
if w.closed.Load() {
return
}
@@ -286,7 +286,7 @@ func (w *WebRTCReceiver) SetUpTrackPaused(paused bool) {
}
func (w *WebRTCReceiver) AddDownTrack(track TrackSender) {
if w.closed.get() {
if w.closed.Load() {
return
}
@@ -351,7 +351,7 @@ func (w *WebRTCReceiver) OnCloseHandler(fn func()) {
// DeleteDownTrack removes a DownTrack from a Receiver
func (w *WebRTCReceiver) DeleteDownTrack(peerID livekit.ParticipantID) {
if w.closed.get() {
if w.closed.Load() {
return
}
@@ -368,7 +368,7 @@ func (w *WebRTCReceiver) DeleteDownTrack(peerID livekit.ParticipantID) {
}
func (w *WebRTCReceiver) sendRTCP(packets []rtcp.Packet) {
if w.closed.get() {
if w.closed.Load() {
return
}
@@ -446,7 +446,7 @@ func (w *WebRTCReceiver) forwardRTP(layer int32) {
defer func() {
w.closeOnce.Do(func() {
w.closed.set(true)
w.closed.Store(true)
w.closeTracks()
})
@@ -479,7 +479,7 @@ func (w *WebRTCReceiver) forwardRTP(layer int32) {
}
} else {
// parallel - enables much more efficient multi-core utilization
start := uint64(0)
start := atomic.NewUint64(0)
end := uint64(len(downTracks))
// 100µs is enough to amortize the overhead and provide sufficient load balancing.
@@ -492,7 +492,7 @@ func (w *WebRTCReceiver) forwardRTP(layer int32) {
go func() {
defer wg.Done()
for {
n := atomic.AddUint64(&start, step)
n := start.Add(step)
if n >= end+step {
return
}