diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-06-13 07:07:33 -0600 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-06-13 07:07:33 -0600 |
commit | 01bc9be72f46f0f1978b1f1581440c399b3a7684 (patch) | |
tree | df5b1d1f28d356ec846c32c2f3a3b1953d693b3c /bolt_linux.go | |
parent | Merge pull request #190 from Shopify/cursor_delete (diff) | |
parent | Remove errcheck. (diff) | |
download | dedo-01bc9be72f46f0f1978b1f1581440c399b3a7684.tar.gz dedo-01bc9be72f46f0f1978b1f1581440c399b3a7684.tar.xz |
Merge pull request #191 from benbjohnson/win-ftw
Windows Support
Diffstat (limited to 'bolt_linux.go')
-rw-r--r-- | bolt_linux.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/bolt_linux.go b/bolt_linux.go index 4351db5..761a83e 100644 --- a/bolt_linux.go +++ b/bolt_linux.go @@ -3,10 +3,51 @@ package bolt import ( "os" "syscall" + "unsafe" ) var odirect = syscall.O_DIRECT +// fdatasync flushes written data to a file descriptor. func fdatasync(f *os.File) error { return syscall.Fdatasync(int(f.Fd())) } + +// flock acquires an advisory lock on a file descriptor. +func flock(f *os.File) error { + return syscall.Flock(int(f.Fd()), syscall.LOCK_EX) +} + +// funlock releases an advisory lock on a file descriptor. +func funlock(f *os.File) error { + return syscall.Flock(int(f.Fd()), syscall.LOCK_UN) +} + +// mmap memory maps a DB's data file. +func mmap(db *DB, sz int) error { + b, err := syscall.Mmap(int(db.file.Fd()), 0, sz, syscall.PROT_READ, syscall.MAP_SHARED) + if err != nil { + return err + } + + // Save the original byte slice and convert to a byte array pointer. + db.dataref = b + db.data = (*[maxMapSize]byte)(unsafe.Pointer(&b[0])) + db.datasz = sz + return nil +} + +// munmap unmaps a DB's data file from memory. +func munmap(db *DB) error { + // Ignore the unmap if we have no mapped data. + if db.dataref == nil { + return nil + } + + // Unmap using the original byte slice. + err := syscall.Munmap(db.dataref) + db.dataref = nil + db.data = nil + db.datasz = 0 + return err +} |