Browse Source

Merge pull request #3 from fancycode/prevent_duplicate_rooms

Prevent duplicate room creation.
pull/4/head
Simon Eisenmann 12 years ago
parent
commit
a5957fc207
  1. 7
      src/app/spreed-speakfreely-server/hub.go

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

@ -164,6 +164,10 @@ func (h *Hub) GetRoom(id string) *RoomWorker { @@ -164,6 +164,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()
@ -176,6 +180,9 @@ func (h *Hub) GetRoom(id string) *RoomWorker { @@ -176,6 +180,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