返回 last30days-skill
cache_lock_windows.go
根目录 / mcp / internal / engine / cache_lock_windows.go
1 package engine
2
3 import (
4 "os"
5 "syscall"
6 "unsafe"
7 )
8
9 var lockFileEx = syscall.NewLazyDLL("kernel32.dll").NewProc("LockFileEx")
10
11 func tryLockCacheFile(file *os.File) (bool, error) {
12 const exclusiveLock = 0x00000002
13 const failImmediately = 0x00000001
14 const lockViolation = syscall.Errno(33)
15 var overlapped syscall.Overlapped
16 result, _, err := lockFileEx.Call(file.Fd(), exclusiveLock|failImmediately, 0, 1, 0, uintptr(unsafe.Pointer(&overlapped)))
17 if result == 0 {
18 if err == lockViolation {
19 return false, nil
20 }
21 return false, err
22 }
23 return true, nil
24 }
25
25 lines GO