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:
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"go.uber.org/atomic"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
@@ -18,7 +18,7 @@ type LocalRouter struct {
|
||||
// channels for each participant
|
||||
requestChannels map[string]*MessageChannel
|
||||
responseChannels map[string]*MessageChannel
|
||||
isStarted utils.AtomicFlag
|
||||
isStarted atomic.Bool
|
||||
|
||||
rtcMessageChan *MessageChannel
|
||||
|
||||
@@ -147,7 +147,7 @@ func (r *LocalRouter) OnRTCMessage(callback RTCMessageCallback) {
|
||||
}
|
||||
|
||||
func (r *LocalRouter) Start() error {
|
||||
if !r.isStarted.TrySet(true) {
|
||||
if r.isStarted.Swap(true) {
|
||||
return nil
|
||||
}
|
||||
go r.statsWorker()
|
||||
@@ -166,7 +166,7 @@ func (r *LocalRouter) Stop() {
|
||||
|
||||
func (r *LocalRouter) statsWorker() {
|
||||
for {
|
||||
if !r.isStarted.Get() {
|
||||
if !r.isStarted.Load() {
|
||||
return
|
||||
}
|
||||
// update every 10 seconds
|
||||
@@ -179,7 +179,7 @@ func (r *LocalRouter) statsWorker() {
|
||||
|
||||
func (r *LocalRouter) rtcMessageWorker() {
|
||||
// is a new channel available? if so swap to that one
|
||||
if !r.isStarted.Get() {
|
||||
if !r.isStarted.Load() {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/go-redis/redis/v8"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"go.uber.org/atomic"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
@@ -96,7 +96,7 @@ type RTCNodeSink struct {
|
||||
rc *redis.Client
|
||||
nodeID livekit.NodeID
|
||||
participantKey livekit.ParticipantKey
|
||||
isClosed utils.AtomicFlag
|
||||
isClosed atomic.Bool
|
||||
onClose func()
|
||||
}
|
||||
|
||||
@@ -109,14 +109,14 @@ func NewRTCNodeSink(rc *redis.Client, nodeID livekit.NodeID, participantKey live
|
||||
}
|
||||
|
||||
func (s *RTCNodeSink) WriteMessage(msg proto.Message) error {
|
||||
if s.isClosed.Get() {
|
||||
if s.isClosed.Load() {
|
||||
return ErrChannelClosed
|
||||
}
|
||||
return publishRTCMessage(s.rc, s.nodeID, s.participantKey, msg)
|
||||
}
|
||||
|
||||
func (s *RTCNodeSink) Close() {
|
||||
if !s.isClosed.TrySet(true) {
|
||||
if s.isClosed.Swap(true) {
|
||||
return
|
||||
}
|
||||
if s.onClose != nil {
|
||||
@@ -132,7 +132,7 @@ type SignalNodeSink struct {
|
||||
rc *redis.Client
|
||||
nodeID livekit.NodeID
|
||||
connectionID livekit.ConnectionID
|
||||
isClosed utils.AtomicFlag
|
||||
isClosed atomic.Bool
|
||||
onClose func()
|
||||
}
|
||||
|
||||
@@ -145,14 +145,14 @@ func NewSignalNodeSink(rc *redis.Client, nodeID livekit.NodeID, connectionID liv
|
||||
}
|
||||
|
||||
func (s *SignalNodeSink) WriteMessage(msg proto.Message) error {
|
||||
if s.isClosed.Get() {
|
||||
if s.isClosed.Load() {
|
||||
return ErrChannelClosed
|
||||
}
|
||||
return publishSignalMessage(s.rc, s.nodeID, s.connectionID, msg)
|
||||
}
|
||||
|
||||
func (s *SignalNodeSink) Close() {
|
||||
if !s.isClosed.TrySet(true) {
|
||||
if s.isClosed.Swap(true) {
|
||||
return
|
||||
}
|
||||
_ = publishSignalMessage(s.rc, s.nodeID, s.connectionID, &livekit.EndSession{})
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/atomic"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/routing/selector"
|
||||
@@ -31,7 +32,7 @@ type RedisRouter struct {
|
||||
|
||||
rc *redis.Client
|
||||
ctx context.Context
|
||||
isStarted utils.AtomicFlag
|
||||
isStarted atomic.Bool
|
||||
|
||||
pubsub *redis.PubSub
|
||||
cancel func()
|
||||
@@ -278,7 +279,7 @@ func (r *RedisRouter) startParticipantRTC(ss *livekit.StartSession, participantK
|
||||
}
|
||||
|
||||
func (r *RedisRouter) Start() error {
|
||||
if !r.isStarted.TrySet(true) {
|
||||
if r.isStarted.Swap(true) {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -303,7 +304,7 @@ func (r *RedisRouter) Drain() {
|
||||
}
|
||||
|
||||
func (r *RedisRouter) Stop() {
|
||||
if !r.isStarted.TrySet(false) {
|
||||
if !r.isStarted.Swap(false) {
|
||||
return
|
||||
}
|
||||
logger.Debugw("stopping RedisRouter")
|
||||
|
||||
Reference in New Issue
Block a user