From e88787a75a7e3857fc3d7185ba126f96fd659b27 Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Wed, 23 Jan 2019 15:11:08 +0100 Subject: [PATCH] lock db methods --- server/mapobjectdb/sqlite_tiles.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/mapobjectdb/sqlite_tiles.go b/server/mapobjectdb/sqlite_tiles.go index d801d62..95741cb 100644 --- a/server/mapobjectdb/sqlite_tiles.go +++ b/server/mapobjectdb/sqlite_tiles.go @@ -4,6 +4,7 @@ import ( "database/sql" _ "github.com/mattn/go-sqlite3" "mapserver/coords" + "sync" ) const getTileQuery = ` @@ -47,13 +48,17 @@ func (db *Sqlite3Accessor) GetTile(pos *coords.TileCoords) (*Tile, error) { return nil, nil } +var mutex = &sync.RWMutex{} + const setTileQuery = ` insert or replace into tiles(x,y,zoom,layerid,data,mtime) values(?, ?, ?, ?, ?, ?) ` func (db *Sqlite3Accessor) SetTile(tile *Tile) error { + mutex.Lock() _, err := db.db.Exec(setTileQuery, tile.Pos.X, tile.Pos.Y, tile.Pos.Zoom, tile.Pos.LayerId, tile.Data, tile.Mtime) + mutex.Unlock() return err } @@ -63,7 +68,9 @@ where x = ? and y = ? and zoom = ? and layerid = ? ` func (db *Sqlite3Accessor) RemoveTile(pos *coords.TileCoords) error { + mutex.Lock() _, err := db.db.Exec(removeTileQuery, pos.X, pos.Y, pos.Zoom, pos.LayerId) + mutex.Unlock() return err }