go.mod: github.com/alexflint/go-filemutex v1.1.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2021-03-12 17:24:03 +01:00
parent 75b64e0f60
commit c3d01539d5
8 changed files with 54 additions and 10 deletions

View File

@ -35,6 +35,18 @@ func (m *FileMutex) Lock() error {
return nil
}
func (m *FileMutex) TryLock() error {
if err := syscall.Flock(m.fd, syscall.LOCK_EX|syscall.LOCK_NB); err != nil {
if errno, ok := err.(syscall.Errno); ok {
if errno == syscall.EWOULDBLOCK {
return AlreadyLocked
}
}
return err
}
return nil
}
func (m *FileMutex) Unlock() error {
if err := syscall.Flock(m.fd, syscall.LOCK_UN); err != nil {
return err
@ -56,9 +68,7 @@ func (m *FileMutex) RUnlock() error {
return nil
}
// Close does an Unlock() combined with closing and unlinking the associated
// lock file. You should create a New() FileMutex for every Lock() attempt if
// using Close().
// Close unlocks the lock and closes the underlying file descriptor.
func (m *FileMutex) Close() error {
if err := syscall.Flock(m.fd, syscall.LOCK_UN); err != nil {
return err