add mutex for windows lockedFiles map
This commit is contained in:
parent
11d601ad6d
commit
370a4ca70b
|
@ -5,6 +5,7 @@ package state
|
||||||
import (
|
import (
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
@ -18,7 +19,8 @@ var (
|
||||||
procLockFileEx = modkernel32.NewProc("LockFileEx")
|
procLockFileEx = modkernel32.NewProc("LockFileEx")
|
||||||
procCreateEventW = modkernel32.NewProc("CreateEventW")
|
procCreateEventW = modkernel32.NewProc("CreateEventW")
|
||||||
|
|
||||||
lockedFiles = map[*os.File]syscall.Handle{}
|
lockedFilesMu sync.Mutex
|
||||||
|
lockedFiles = map[*os.File]syscall.Handle{}
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -27,6 +29,9 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *LocalState) lock() error {
|
func (s *LocalState) lock() error {
|
||||||
|
lockedFilesMu.Lock()
|
||||||
|
defer lockedFilesMu.Unlock()
|
||||||
|
|
||||||
name, err := syscall.UTF16PtrFromString(s.PathOut)
|
name, err := syscall.UTF16PtrFromString(s.PathOut)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -68,6 +73,9 @@ func (s *LocalState) lock() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *LocalState) unlock() error {
|
func (s *LocalState) unlock() error {
|
||||||
|
lockedFilesMu.Lock()
|
||||||
|
defer lockedFilesMu.Unlock()
|
||||||
|
|
||||||
handle, ok := lockedFiles[s.stateFileOut]
|
handle, ok := lockedFiles[s.stateFileOut]
|
||||||
if !ok {
|
if !ok {
|
||||||
// we allow multiple Unlock calls
|
// we allow multiple Unlock calls
|
||||||
|
|
Loading…
Reference in New Issue