|
|
|
@ -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() |
|
|
|
|
} |
|
|
|
|