From e185365e2d2bdc9c940be84e2fc8fce6f973ae08 Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Sat, 29 Mar 2014 01:57:29 -0700 Subject: [PATCH] moved MapLock to control --- control.go | 22 ++++++++++++++++++++++ game.go | 21 --------------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/control.go b/control.go index feb26bc..4f0280e 100644 --- a/control.go +++ b/control.go @@ -10,6 +10,7 @@ import ( "os" "runtime/pprof" "strings" + "sync" ) type JsonHandler func(http.ResponseWriter, *http.Request) @@ -252,3 +253,24 @@ func (c *Controller) getGameId(path string) (string, error) { key := fullPath[2] return key, err } + +type MapLock struct { + M map[string]*Game + sync.RWMutex +} + +// get is a function that returns a game if found, and creates one if +// not found and force is true. In order to get a hash (rather than use +// the string you pass) send "" for id. +func (ml *MapLock) get(id string) *Game { + ml.Lock() + g, _ := ml.M[id] + ml.Unlock() + return g +} + +func (ml *MapLock) add(g *Game) { + ml.Lock() + ml.M[g.id] = g + ml.Unlock() +} diff --git a/game.go b/game.go index fba3e2d..ad4e794 100644 --- a/game.go +++ b/game.go @@ -23,27 +23,6 @@ type Scanner struct { Type string `json:"type"` } -type MapLock struct { - M map[string]*Game - sync.RWMutex -} - -// get is a function that returns a game if found, and creates one if -// not found and force is true. In order to get a hash (rather than use -// the string you pass) send "" for id. -func (ml *MapLock) get(id string) *Game { - ml.Lock() - g, _ := ml.M[id] - ml.Unlock() - return g -} - -func (ml *MapLock) add(g *Game) { - ml.Lock() - ml.M[g.id] = g - ml.Unlock() -} - type BotStats struct { Kills int Deaths int