Use new builtin "clear" to remove map entries.

This commit is contained in:
Joachim Bauch 2024-05-16 11:35:09 +02:00
parent d03ea86991
commit fdc43d12cd
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02
5 changed files with 12 additions and 6 deletions

View file

@ -280,6 +280,8 @@ func (e *asyncEventsNats) Close() {
sub.close()
}
}(e.sessionSubscriptions)
// Can't use clear(...) here as the maps are processed asynchronously by the
// goroutines above.
e.backendRoomSubscriptions = make(map[string]*asyncBackendRoomSubscriberNats)
e.roomSubscriptions = make(map[string]*asyncRoomSubscriberNats)
e.userSubscriptions = make(map[string]*asyncUserSubscriberNats)

View file

@ -310,7 +310,7 @@ func (gateway *JanusGateway) cancelTransactions() {
t.quit()
}(t)
}
gateway.transactions = make(map[uint64]*transaction)
clear(gateway.transactions)
gateway.Unlock()
}

View file

@ -250,7 +250,7 @@ func (m *mcuJanus) doReconnect() {
log.Println("Reconnection to Janus gateway successful")
m.mu.Lock()
m.publishers = make(map[string]*mcuJanusPublisher)
clear(m.publishers)
m.publisherCreated.Reset()
m.publisherConnected.Reset()
m.reconnectInterval = initialReconnectInterval

View file

@ -746,8 +746,9 @@ func (c *mcuProxyConnection) clearPublishers() {
publisher.NotifyClosed()
}
}(c.publishers)
// Can't use clear(...) here as the map is processed by the goroutine above.
c.publishers = make(map[string]*mcuProxyPublisher)
c.publisherIds = make(map[string]string)
clear(c.publisherIds)
if c.closeScheduled.Load() || c.IsTemporary() {
go c.closeIfEmpty()
@ -777,6 +778,7 @@ func (c *mcuProxyConnection) clearSubscribers() {
subscriber.NotifyClosed()
}
}(c.subscribers)
// Can't use clear(...) here as the map is processed by the goroutine above.
c.subscribers = make(map[string]*mcuProxySubscriber)
if c.closeScheduled.Load() || c.IsTemporary() {
@ -788,7 +790,7 @@ func (c *mcuProxyConnection) clearCallbacks() {
c.mu.Lock()
defer c.mu.Unlock()
c.callbacks = make(map[string]func(*ProxyServerMessage))
clear(c.callbacks)
}
func (c *mcuProxyConnection) getCallback(id string) func(*ProxyServerMessage) {

View file

@ -299,8 +299,9 @@ func (s *ProxySession) clearPublishers() {
publisher.Close(context.Background())
}
}(s.publishers)
// Can't use clear(...) here as the map is processed by the goroutine above.
s.publishers = make(map[string]signaling.McuPublisher)
s.publisherIds = make(map[signaling.McuPublisher]string)
clear(s.publisherIds)
}
func (s *ProxySession) clearSubscribers() {
@ -315,8 +316,9 @@ func (s *ProxySession) clearSubscribers() {
subscriber.Close(context.Background())
}
}(s.subscribers)
// Can't use clear(...) here as the map is processed by the goroutine above.
s.subscribers = make(map[string]signaling.McuSubscriber)
s.subscriberIds = make(map[signaling.McuSubscriber]string)
clear(s.subscriberIds)
}
func (s *ProxySession) NotifyDisconnected() {