Browse Source

moved MapLock to control

master
Stephen McQuay 6 years ago
parent
commit
e185365e2d
2 changed files with 22 additions and 21 deletions
  1. +22
    -0
      control.go
  2. +0
    -21
      game.go

+ 22
- 0
control.go View File

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

+ 0
- 21
game.go View File

@ -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…
Cancel
Save