Skip to content
This repository was archived by the owner on Mar 9, 2019. It is now read-only.

Commit e9cf4fa

Browse files
authored
Merge pull request #654 from benbjohnson/revert-ca9f208
Revert "replace unix implementation to be the same as solaris to fix …"
2 parents 9145e04 + 82ecdfe commit e9cf4fa

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

bolt_unix.go

+7-17
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,16 @@ func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) erro
2121
} else if timeout > 0 && time.Since(t) > timeout {
2222
return ErrTimeout
2323
}
24-
var lock syscall.Flock_t
25-
lock.Start = 0
26-
lock.Len = 0
27-
lock.Pid = 0
28-
lock.Whence = 0
29-
lock.Pid = 0
24+
flag := syscall.LOCK_SH
3025
if exclusive {
31-
lock.Type = syscall.F_WRLCK
32-
} else {
33-
lock.Type = syscall.F_RDLCK
26+
flag = syscall.LOCK_EX
3427
}
35-
err := syscall.FcntlFlock(db.file.Fd(), syscall.F_SETLK, &lock)
28+
29+
// Otherwise attempt to obtain an exclusive lock.
30+
err := syscall.Flock(int(db.file.Fd()), flag|syscall.LOCK_NB)
3631
if err == nil {
3732
return nil
38-
} else if err != syscall.EAGAIN {
33+
} else if err != syscall.EWOULDBLOCK {
3934
return err
4035
}
4136

@@ -46,12 +41,7 @@ func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) erro
4641

4742
// funlock releases an advisory lock on a file descriptor.
4843
func funlock(db *DB) error {
49-
var lock syscall.Flock_t
50-
lock.Start = 0
51-
lock.Len = 0
52-
lock.Type = syscall.F_UNLCK
53-
lock.Whence = 0
54-
return syscall.FcntlFlock(uintptr(db.file.Fd()), syscall.F_SETLK, &lock)
44+
return syscall.Flock(int(db.file.Fd()), syscall.LOCK_UN)
5545
}
5646

5747
// mmap memory maps a DB's data file.

0 commit comments

Comments
 (0)