aboutsummaryrefslogtreecommitdiff
path: root/bolt_unix.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2017-01-31 12:20:18 -0700
committerGitHub <noreply@github.com>2017-01-31 12:20:18 -0700
commite9cf4fae01b5a8ff89d0ec6b32f0d9c9f79aefdd (patch)
tree4f9c4486e1fb31ceea335d15aa3bda4e99155021 /bolt_unix.go
parentMerge pull request #651 from zweizeichen/master (diff)
parentRevert "replace unix implementation to be the same as solaris to fix an issue... (diff)
downloaddedo-e9cf4fae01b5a8ff89d0ec6b32f0d9c9f79aefdd.tar.gz
dedo-e9cf4fae01b5a8ff89d0ec6b32f0d9c9f79aefdd.tar.xz
Merge pull request #654 from benbjohnson/revert-ca9f208
Revert "replace unix implementation to be the same as solaris to fix …"
Diffstat (limited to 'bolt_unix.go')
-rw-r--r--bolt_unix.go24
1 files changed, 7 insertions, 17 deletions
diff --git a/bolt_unix.go b/bolt_unix.go
index 50cbbc0..cad62dd 100644
--- a/bolt_unix.go
+++ b/bolt_unix.go
@@ -21,21 +21,16 @@ func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) erro
} else if timeout > 0 && time.Since(t) > timeout {
return ErrTimeout
}
- var lock syscall.Flock_t
- lock.Start = 0
- lock.Len = 0
- lock.Pid = 0
- lock.Whence = 0
- lock.Pid = 0
+ flag := syscall.LOCK_SH
if exclusive {
- lock.Type = syscall.F_WRLCK
- } else {
- lock.Type = syscall.F_RDLCK
+ flag = syscall.LOCK_EX
}
- err := syscall.FcntlFlock(db.file.Fd(), syscall.F_SETLK, &lock)
+
+ // Otherwise attempt to obtain an exclusive lock.
+ err := syscall.Flock(int(db.file.Fd()), flag|syscall.LOCK_NB)
if err == nil {
return nil
- } else if err != syscall.EAGAIN {
+ } else if err != syscall.EWOULDBLOCK {
return err
}
@@ -46,12 +41,7 @@ func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) erro
// funlock releases an advisory lock on a file descriptor.
func funlock(db *DB) error {
- var lock syscall.Flock_t
- lock.Start = 0
- lock.Len = 0
- lock.Type = syscall.F_UNLCK
- lock.Whence = 0
- return syscall.FcntlFlock(uintptr(db.file.Fd()), syscall.F_SETLK, &lock)
+ return syscall.Flock(int(db.file.Fd()), syscall.LOCK_UN)
}
// mmap memory maps a DB's data file.