Browse Source

Prevent duplicate room creation.

pull/3/head
Joachim Bauch 12 years ago
parent
commit
bc5aee4658
  1. 31
      src/app/spreed-speakfreely-server/hub.go

31
src/app/spreed-speakfreely-server/hub.go

@ -161,18 +161,25 @@ func (h *Hub) GetRoom(id string) *RoomWorker {
if !ok { if !ok {
h.mutex.RUnlock() h.mutex.RUnlock()
h.mutex.Lock() h.mutex.Lock()
room = NewRoomWorker(h, id) // need to re-check, another thread might have created the room
h.roomTable[id] = room // while we waited for the lock
h.mutex.Unlock() room, ok = h.roomTable[id]
go func() { if !ok {
// Start room, this blocks until room expired. room = NewRoomWorker(h, id)
room.Start() h.roomTable[id] = room
// Cleanup room when we are done. h.mutex.Unlock()
h.mutex.Lock() go func() {
defer h.mutex.Unlock() // Start room, this blocks until room expired.
delete(h.roomTable, id) room.Start()
log.Printf("Cleaned up room '%s'\n", id) // Cleanup room when we are done.
}() h.mutex.Lock()
defer h.mutex.Unlock()
delete(h.roomTable, id)
log.Printf("Cleaned up room '%s'\n", id)
}()
} else {
h.mutex.Unlock()
}
} else { } else {
h.mutex.RUnlock() h.mutex.RUnlock()
} }

Loading…
Cancel
Save