add mutex for windows lockedFiles map

This commit is contained in:
James Bardin 2017-02-01 12:36:08 -05:00
parent 11d601ad6d
commit 370a4ca70b
1 changed files with 9 additions and 1 deletions

View File

@ -5,6 +5,7 @@ package state
import (
"math"
"os"
"sync"
"syscall"
"unsafe"
)
@ -18,7 +19,8 @@ var (
procLockFileEx = modkernel32.NewProc("LockFileEx")
procCreateEventW = modkernel32.NewProc("CreateEventW")
lockedFiles = map[*os.File]syscall.Handle{}
lockedFilesMu sync.Mutex
lockedFiles = map[*os.File]syscall.Handle{}
)
const (
@ -27,6 +29,9 @@ const (
)
func (s *LocalState) lock() error {
lockedFilesMu.Lock()
defer lockedFilesMu.Unlock()
name, err := syscall.UTF16PtrFromString(s.PathOut)
if err != nil {
return err
@ -68,6 +73,9 @@ func (s *LocalState) lock() error {
}
func (s *LocalState) unlock() error {
lockedFilesMu.Lock()
defer lockedFilesMu.Unlock()
handle, ok := lockedFiles[s.stateFileOut]
if !ok {
// we allow multiple Unlock calls