mirror of
https://github.com/livekit/livekit.git
synced 2026-08-29 07:39:09 +00:00
use atomic.Load to ensure atomicity
This commit is contained in:
+20
-6
@@ -29,7 +29,6 @@ func initLogger(config zap.Config, level string) {
|
||||
|
||||
func InitProduction(logLevel string) {
|
||||
initLogger(zap.NewProductionConfig(), logLevel)
|
||||
|
||||
}
|
||||
|
||||
func InitDevelopment(logLevel string) {
|
||||
@@ -37,21 +36,36 @@ func InitDevelopment(logLevel string) {
|
||||
}
|
||||
|
||||
func Debugw(msg string, keysAndValues ...interface{}) {
|
||||
getLogger().Debugw(msg, keysAndValues...)
|
||||
if logger == nil {
|
||||
return
|
||||
}
|
||||
logger.Debugw(msg, keysAndValues...)
|
||||
}
|
||||
|
||||
func Infow(msg string, keysAndValues ...interface{}) {
|
||||
getLogger().Infow(msg, keysAndValues...)
|
||||
if logger == nil {
|
||||
return
|
||||
}
|
||||
logger.Infow(msg, keysAndValues...)
|
||||
}
|
||||
|
||||
func Warnw(msg string, keysAndValues ...interface{}) {
|
||||
getLogger().Warnw(msg, keysAndValues...)
|
||||
if logger == nil {
|
||||
return
|
||||
}
|
||||
logger.Warnw(msg, keysAndValues...)
|
||||
}
|
||||
|
||||
func Errorw(msg string, keysAndValues ...interface{}) {
|
||||
getLogger().Errorw(msg, keysAndValues...)
|
||||
if logger == nil {
|
||||
return
|
||||
}
|
||||
logger.Errorw(msg, keysAndValues...)
|
||||
}
|
||||
|
||||
func Desugar() *zap.Logger {
|
||||
return getLogger().Desugar()
|
||||
if logger == nil {
|
||||
getLogger()
|
||||
}
|
||||
return logger.Desugar()
|
||||
}
|
||||
|
||||
@@ -382,6 +382,7 @@ func (p *ParticipantImpl) SendJoinResponse(roomInfo *livekit.Room, otherParticip
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) SendParticipantUpdate(participants []*livekit.ParticipantInfo) error {
|
||||
|
||||
return p.responseSink.WriteMessage(&livekit.SignalResponse{
|
||||
Message: &livekit.SignalResponse_Update{
|
||||
Update: &livekit.ParticipantUpdate{
|
||||
|
||||
+7
-7
@@ -10,25 +10,25 @@ var (
|
||||
)
|
||||
|
||||
type AtomicFlag struct {
|
||||
val uint32
|
||||
val int32
|
||||
}
|
||||
|
||||
// set flag to value if existing flag is different, otherwise return
|
||||
func (b *AtomicFlag) TrySet(bVal bool) bool {
|
||||
var v uint32
|
||||
var v int32
|
||||
if bVal {
|
||||
v = 1
|
||||
}
|
||||
old := b.val
|
||||
// value is the same, nochanges
|
||||
if old == v {
|
||||
prev := atomic.SwapInt32(&b.val, v)
|
||||
// already set. unsuccessful
|
||||
if prev == v {
|
||||
return false
|
||||
}
|
||||
return atomic.CompareAndSwapUint32(&b.val, old, v)
|
||||
return true
|
||||
}
|
||||
|
||||
func (b *AtomicFlag) Get() bool {
|
||||
return b.val == 1
|
||||
return atomic.LoadInt32(&b.val) == 1
|
||||
}
|
||||
|
||||
// a channel that ignores writes when it closes instead of panic
|
||||
|
||||
Reference in New Issue
Block a user