Replace sync/atomic usage with uber/atomic (#471)
This commit is contained in:
+3
-3
@@ -109,11 +109,11 @@ package sfu
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/gammazero/deque"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"go.uber.org/atomic"
|
||||
)
|
||||
|
||||
type ProberParams struct {
|
||||
@@ -123,7 +123,7 @@ type ProberParams struct {
|
||||
type Prober struct {
|
||||
logger logger.Logger
|
||||
|
||||
clusterId uint32
|
||||
clusterId atomic.Uint32
|
||||
|
||||
clustersMu sync.RWMutex
|
||||
clusters deque.Deque
|
||||
@@ -179,7 +179,7 @@ func (p *Prober) AddCluster(desiredRateBps int, expectedRateBps int, minDuration
|
||||
return ProbeClusterIdInvalid
|
||||
}
|
||||
|
||||
clusterId := ProbeClusterId(atomic.AddUint32(&p.clusterId, 1))
|
||||
clusterId := ProbeClusterId(p.clusterId.Inc())
|
||||
cluster := NewCluster(clusterId, desiredRateBps, expectedRateBps, minDuration, maxDuration)
|
||||
p.logger.Debugw("cluster added", "cluster", cluster.String())
|
||||
|
||||
|
||||
@@ -6,11 +6,11 @@ import (
|
||||
"math/rand"
|
||||
"runtime"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
|
||||
"github.com/gammazero/workerpool"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/atomic"
|
||||
)
|
||||
|
||||
func TestWebRTCReceiver_OnCloseHandler(t *testing.T) {
|
||||
@@ -137,7 +137,7 @@ func benchmarkGoroutine(b *testing.B, buckets []int) {
|
||||
|
||||
func benchmarkLoadBalanced(b *testing.B, numProcs, step, downTracks int) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
start := uint64(0)
|
||||
start := atomic.NewUint64(0)
|
||||
step := uint64(step)
|
||||
end := uint64(downTracks)
|
||||
|
||||
@@ -147,7 +147,7 @@ func benchmarkLoadBalanced(b *testing.B, numProcs, step, downTracks int) {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
for {
|
||||
n := atomic.AddUint64(&start, step)
|
||||
n := start.Add(step)
|
||||
if n >= end+step {
|
||||
return
|
||||
}
|
||||
@@ -164,7 +164,7 @@ func benchmarkLoadBalanced(b *testing.B, numProcs, step, downTracks int) {
|
||||
|
||||
func benchmarkLoadBalancedPool(b *testing.B, wp *workerpool.WorkerPool, numProcs, step, downTracks int) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
start := uint64(0)
|
||||
start := atomic.NewUint64(0)
|
||||
step := uint64(step)
|
||||
end := uint64(downTracks)
|
||||
|
||||
@@ -174,7 +174,7 @@ func benchmarkLoadBalancedPool(b *testing.B, wp *workerpool.WorkerPool, numProcs
|
||||
wp.Submit(func() {
|
||||
defer wg.Done()
|
||||
for {
|
||||
n := atomic.AddUint64(&start, step)
|
||||
n := start.Add(step)
|
||||
if n >= end+step {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user