update shm methods

This commit is contained in:
hslam 2020-12-01 16:08:25 +08:00
parent f15816045d
commit 69c6385272
3 changed files with 22 additions and 22 deletions

View File

@ -56,9 +56,9 @@ func main() {
}
}
defer ipc.Semrm(semid)
shmid, data, _ := ipc.Shmgetat(key, 128, ipc.IPC_CREAT|0600)
shmid, data, _ := ipc.Shmgetattach(key, 128, ipc.IPC_CREAT|0600)
defer ipc.Shmrm(shmid)
defer ipc.Shmdt(data)
defer ipc.Shmdetach(data)
msgid, _ := ipc.Msgget(key, ipc.IPC_CREAT|0600)
defer ipc.Msgrm(msgid)
var text string

View File

@ -29,9 +29,9 @@ func TestIPC(t *testing.T) {
}
}
defer Semrm(semid)
shmid, data, _ := Shmgetat(key, 128, IPC_CREAT|0600)
shmid, data, _ := Shmgetattach(key, 128, IPC_CREAT|0600)
defer Shmrm(shmid)
defer Shmdt(data)
defer Shmdetach(data)
msgid, _ := Msgget(key, IPC_CREAT|0600)
defer Msgrm(msgid)
if _, err := Semp(semid, semnum, SEM_UNDO); err != nil {
@ -63,9 +63,9 @@ func TestIPC(t *testing.T) {
}
}
defer Semrm(semid)
shmid, data, _ := Shmgetat(key, 128, 0600)
shmid, data, _ := Shmgetattach(key, 128, 0600)
defer Shmrm(shmid)
defer Shmdt(data)
defer Shmdetach(data)
msgid, _ := Msgget(key, 0600)
defer Msgrm(msgid)
@ -111,9 +111,9 @@ func TestMore(t *testing.T) {
}
}
defer Semrm(semid)
shmid, data, _ := Shmgetat(key, 128, IPC_CREAT|0600)
shmid, data, _ := Shmgetattach(key, 128, IPC_CREAT|0600)
defer Shmrm(shmid)
defer Shmdt(data)
defer Shmdetach(data)
msgid, _ := Msgget(key, IPC_CREAT|0600)
defer Msgrm(msgid)
if _, err := Semp(semid, semnum, SEM_UNDO); err != nil {
@ -148,14 +148,14 @@ func TestMore(t *testing.T) {
size := 128
shmid, _ := Shmget(key, size, 0600)
defer Shmrm(shmid)
shmaddr, _ := Shmattach(shmid, 0600)
shmaddr, _ := Shmat(shmid, 0600)
var sl = struct {
addr uintptr
len int
cap int
}{shmaddr, size, size}
data := *(*[]byte)(unsafe.Pointer(&sl))
defer Shmdetach(shmaddr)
defer Shmdt(shmaddr)
msgid, _ := Msgget(key, 0600)
defer Msgrm(msgid)

24
shm.go
View File

@ -12,24 +12,24 @@ func Shmget(key int, size int, shmFlg int) (int, error) {
return shm.Get(key, size, shmFlg)
}
// Shmattach calls the shmat system call.
func Shmattach(shmid int, shmFlg int) (uintptr, error) {
return shm.Attach(shmid, shmFlg)
// Shmat calls the shmat system call.
func Shmat(shmid int, shmFlg int) (uintptr, error) {
return shm.At(shmid, shmFlg)
}
// Shmdetach calls the shmdt system call.
func Shmdetach(addr uintptr) error {
return shm.Detach(addr)
// Shmdt calls the shmdt system call.
func Shmdt(addr uintptr) error {
return shm.Dt(addr)
}
// Shmgetat calls the shmget and shmat system call.
func Shmgetat(key int, size int, shmFlg int) (int, []byte, error) {
return shm.GetAt(key, size, shmFlg)
// Shmgetattach calls the shmget and shmat system call.
func Shmgetattach(key int, size int, shmFlg int) (int, []byte, error) {
return shm.GetAttach(key, size, shmFlg)
}
// Shmdt calls the shmdt system call with []byte b.
func Shmdt(b []byte) error {
return shm.Dt(b)
// Shmdetach calls the shmdt system call with []byte b.
func Shmdetach(b []byte) error {
return shm.Detach(b)
}
// Shmrm removes the shm with the given id.