From 28fc4d073442c52ac3bf27b9c594f5a03ea1372a Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Mon, 9 Mar 2015 16:05:54 +0100 Subject: [PATCH] Dont lock the player list all the time when serving the GeoJSON over /players. --- cmd/mtwebmapper/players.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/mtwebmapper/players.go b/cmd/mtwebmapper/players.go index 8cfeb5b..647d122 100644 --- a/cmd/mtwebmapper/players.go +++ b/cmd/mtwebmapper/players.go @@ -86,10 +86,12 @@ func (ps *players) run() { func (ps *players) ServeHTTP(rw http.ResponseWriter, r *http.Request) { rw.Header().Set("Content-Type", "application/json") + var pls []*player ps.mu.RLock() - defer ps.mu.RUnlock() + pls = ps.pls + ps.mu.RUnlock() encoder := json.NewEncoder(rw) - if err := encoder.Encode(ps.pls); err != nil { + if err := encoder.Encode(pls); err != nil { log.Printf("error: sending JSON failed: %s\n", err) } }