blob: 6a6c7b3537ebe150de4385c11b4271a7d9734543 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
// +build !windows
package bbolt
import "golang.org/x/sys/unix"
// mlock locks memory of db file
func mlock(db *DB, fileSize int) error {
sizeToLock := fileSize
if sizeToLock > db.datasz {
// Can't lock more than mmaped slice
sizeToLock = db.datasz
}
if err := unix.Mlock(db.dataref[:sizeToLock]); err != nil {
return err
}
return nil
}
//munlock unlocks memory of db file
func munlock(db *DB, fileSize int) error {
if db.dataref == nil {
return nil
}
sizeToUnlock := fileSize
if sizeToUnlock > db.datasz {
// Can't unlock more than mmaped slice
sizeToUnlock = db.datasz
}
if err := unix.Munlock(db.dataref[:sizeToUnlock]); err != nil {
return err
}
return nil
}
|