moved MapLock to control
This commit is contained in:
parent
e02d220026
commit
e185365e2d
22
control.go
22
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()
|
||||
}
|
||||
|
21
game.go
21
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
|
||||
|
Loading…
Reference in New Issue
Block a user