mirror of https://github.com/etcd-io/bbolt.git
Merge pull request #243 from tklauser/madvise-x-sys-unix
Use madvise syscall wrapper from golang.org/x/sys/unixpull/271/head
commit
5082d3bbc2
|
@ -7,6 +7,7 @@ go:
|
|||
- 1.15
|
||||
|
||||
before_install:
|
||||
- go get -v golang.org/x/sys/unix
|
||||
- go get -v honnef.co/go/tools/...
|
||||
- go get -v github.com/kisielk/errcheck
|
||||
|
||||
|
|
13
bolt_unix.go
13
bolt_unix.go
|
@ -7,6 +7,8 @@ import (
|
|||
"syscall"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// flock acquires an advisory lock on a file descriptor.
|
||||
|
@ -55,7 +57,7 @@ func mmap(db *DB, sz int) error {
|
|||
}
|
||||
|
||||
// Advise the kernel that the mmap is accessed randomly.
|
||||
err = madvise(b, syscall.MADV_RANDOM)
|
||||
err = unix.Madvise(b, syscall.MADV_RANDOM)
|
||||
if err != nil && err != syscall.ENOSYS {
|
||||
// Ignore not implemented error in kernel because it still works.
|
||||
return fmt.Errorf("madvise: %s", err)
|
||||
|
@ -82,12 +84,3 @@ func munmap(db *DB) error {
|
|||
db.datasz = 0
|
||||
return err
|
||||
}
|
||||
|
||||
// NOTE: This function is copied from stdlib because it is not available on darwin.
|
||||
func madvise(b []byte, advice int) (err error) {
|
||||
_, _, e1 := syscall.Syscall(syscall.SYS_MADVISE, uintptr(unsafe.Pointer(&b[0])), uintptr(len(b)), uintptr(advice))
|
||||
if e1 != 0 {
|
||||
err = e1
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
2
go.mod
2
go.mod
|
@ -2,4 +2,4 @@ module go.etcd.io/bbolt
|
|||
|
||||
go 1.12
|
||||
|
||||
require golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5
|
||||
require golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1,2 +1,2 @@
|
|||
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 h1:LfCXLvNmTYH9kEmVgqbnsWfruoXZIrh4YBgqVHtDvw0=
|
||||
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d h1:L/IKR6COd7ubZrs2oTnTi73IhgqJ71c9s80WsQnh0Es=
|
||||
golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
|
Loading…
Reference in New Issue