// Unlock unlocks a region of the mapped shared memory func (buf *sharedBuffer) Unlock(offset, length int) error { b := buf.Bytes() err := checkOffsetLength(b, offset, length) if err == nil { err = syscall.Munlock(b[offset : offset+length]) } return os.NewSyscallError("shm: munlock", err) }
func mmapFile(fileName string) (*mmapData, error) { file, err := os.Open(fileName) if err != nil { return nil, err } stat, err := file.Stat() if err != nil { file.Close() return nil, err } size := stat.Size() pageAlignedSize := (size + 4095) &^ 4095 data, err := syscall.Mmap(int(file.Fd()), 0, int(pageAlignedSize), syscall.PROT_READ, syscall.MAP_PRIVATE) if err != nil { file.Close() return nil, err } err = syscall.Mlock(data) if err != nil { syscall.Munmap(data) file.Close() return nil, err } md := &mmapData{file, data[:size]} runtime.SetFinalizer(md, func(m *mmapData) { syscall.Munlock(m.d) syscall.Munmap(m.d) m.f.Close() }) return md, nil }
// Unlock implements Map.Unlock(). func (m *mmap) Unlock() error { m.RLock() defer m.RUnlock() return syscall.Munlock(m.data) }
// Undo lock. func (m Mmap) Unlock() error { return syscall.Munlock(m) }