hslam_shm/shm.go

32 lines
740 B
Go
Raw Normal View History

2020-11-26 19:37:56 +08:00
// Copyright (c) 2020 Meng Huang (mhboy@outlook.com)
// This package is licensed under a MIT license that can be found in the LICENSE file.
2020-11-28 17:25:57 +08:00
// Package shm provides a way to use System V shared memory.
2020-11-26 19:37:56 +08:00
package shm
import (
"os"
2020-11-27 02:01:38 +08:00
"syscall"
)
const (
// O_RDONLY opens the file read-only.
O_RDONLY int = syscall.O_RDONLY
// O_WRONLY opens the file write-only.
O_WRONLY int = syscall.O_WRONLY
// O_RDWR opens the file read-write.
O_RDWR int = syscall.O_RDWR
// O_CREATE creates a new file if none exists.
O_CREATE int = syscall.O_CREAT
2020-11-26 19:37:56 +08:00
)
// validSize returns the valid size.
func validSize(size int64) int64 {
pageSize := int64(os.Getpagesize())
if size%pageSize == 0 {
return size
}
return (size/pageSize + 1) * pageSize
}