no deadlock with tiledb r/w mutex

This commit is contained in:
NatureFreshMilk 2019-02-22 08:54:11 +01:00
parent 3f3a9da23a
commit 5d87c7ebbe

View File

@ -5,8 +5,11 @@ import (
"mapserver/coords"
"os"
"strconv"
"sync"
)
var mutex = &sync.RWMutex{}
func New(path string) (*TileDB, error) {
return &TileDB{
path: path,
@ -32,6 +35,9 @@ func (this *TileDB) GC() {
}
func (this *TileDB) GetTile(pos *coords.TileCoords) ([]byte, error) {
mutex.RLock()
defer mutex.RUnlock()
_, file := this.getDirAndFile(pos)
info, _ := os.Stat(file)
if info != nil {
@ -47,6 +53,9 @@ func (this *TileDB) GetTile(pos *coords.TileCoords) ([]byte, error) {
}
func (this *TileDB) SetTile(pos *coords.TileCoords, tile []byte) error {
mutex.Lock()
defer mutex.Unlock()
dir, file := this.getDirAndFile(pos)
os.MkdirAll(dir, 0700)