Browse Source

Prevent duplicate room creation.

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

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

@ -161,6 +161,10 @@ func (h *Hub) GetRoom(id string) *RoomWorker { @@ -161,6 +161,10 @@ func (h *Hub) GetRoom(id string) *RoomWorker {
if !ok {
h.mutex.RUnlock()
h.mutex.Lock()
// need to re-check, another thread might have created the room
// while we waited for the lock
room, ok = h.roomTable[id]
if !ok {
room = NewRoomWorker(h, id)
h.roomTable[id] = room
h.mutex.Unlock()
@ -173,6 +177,9 @@ func (h *Hub) GetRoom(id string) *RoomWorker { @@ -173,6 +177,9 @@ func (h *Hub) GetRoom(id string) *RoomWorker {
delete(h.roomTable, id)
log.Printf("Cleaned up room '%s'\n", id)
}()
} else {
h.mutex.Unlock()
}
} else {
h.mutex.RUnlock()
}

Loading…
Cancel
Save