mirror of
https://github.com/jech/galene.git
synced 2024-11-10 02:35:58 +01:00
Avoid deadlock in DelLocal.
This commit is contained in:
parent
0c8df661b2
commit
f8d2bb93e8
1 changed files with 9 additions and 6 deletions
|
@ -211,30 +211,33 @@ func (up *rtpUpTrack) notifyLocal(add bool, track conn.DownTrack) {
|
|||
|
||||
func (up *rtpUpTrack) AddLocal(local conn.DownTrack) error {
|
||||
up.mu.Lock()
|
||||
defer up.mu.Unlock()
|
||||
|
||||
for _, t := range up.local {
|
||||
if t == local {
|
||||
up.mu.Unlock()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
up.local = append(up.local, local)
|
||||
up.mu.Unlock()
|
||||
|
||||
up.notifyLocal(true, local)
|
||||
// do this asynchronously, to avoid deadlocks when multiple
|
||||
// clients call this simultaneously.
|
||||
go up.notifyLocal(true, local)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (up *rtpUpTrack) DelLocal(local conn.DownTrack) bool {
|
||||
up.mu.Lock()
|
||||
defer up.mu.Unlock()
|
||||
for i, l := range up.local {
|
||||
if l == local {
|
||||
up.local = append(up.local[:i], up.local[i+1:]...)
|
||||
up.mu.Unlock()
|
||||
up.notifyLocal(false, l)
|
||||
// do this asynchronously, to avoid deadlocking when
|
||||
// multiple clients call this simultaneously.
|
||||
go up.notifyLocal(false, l)
|
||||
return true
|
||||
}
|
||||
}
|
||||
up.mu.Unlock()
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue