aboutsummaryrefslogtreecommitdiff
path: root/bolt_darwin.go
diff options
context:
space:
mode:
Diffstat (limited to 'bolt_darwin.go')
-rw-r--r--bolt_darwin.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/bolt_darwin.go b/bolt_darwin.go
new file mode 100644
index 0000000..2bffad3
--- /dev/null
+++ b/bolt_darwin.go
@@ -0,0 +1,53 @@
+package bolt
+
+import (
+ "os"
+ "syscall"
+ "unsafe"
+)
+
+var odirect int
+
+// fdatasync flushes written data to a file descriptor.
+func fdatasync(f *os.File) error {
+ return f.Sync()
+}
+
+// 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
+}