mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-14 01:24:04 -08:00
baca6faa1c
This mimics the locking leveldb is performing anyway. Advantages of doing it separately: - Should we ever replace the leveldb implementation by one without double-start protection, we are still good. - In contrast to leveldb, the new code creates a meaningful error message.
24 lines
515 B
Go
24 lines
515 B
Go
package flock
|
|
|
|
import "syscall"
|
|
|
|
type windowsLock struct {
|
|
fd syscall.Handle
|
|
}
|
|
|
|
func (fl *windowsLock) Release() error {
|
|
return syscall.Close(fl.fd)
|
|
}
|
|
|
|
func newLock(fileName string) (Releaser, error) {
|
|
pathp, err := syscall.UTF16PtrFromString(fileName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
fd, err := syscall.CreateFile(pathp, syscall.GENERIC_READ|syscall.GENERIC_WRITE, 0, nil, syscall.CREATE_ALWAYS, syscall.FILE_ATTRIBUTE_NORMAL, 0)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &windowsFileLock{fd}, nil
|
|
}
|