1
0
mirror of https://github.com/hslam/sem.git synced 2025-04-25 13:48:52 +08:00

fix linux bug

This commit is contained in:
hslam 2020-11-28 21:58:30 +08:00
parent 9d8b15138a
commit 6bc5630462
3 changed files with 49 additions and 16 deletions

23
sem_bsd.go Normal file
View File

@ -0,0 +1,23 @@
// Copyright (c) 2020 Meng Huang (mhboy@outlook.com)
// This package is licensed under a MIT license that can be found in the LICENSE file.
// +build darwin dragonfly freebsd netbsd openbsd
package sem
const (
// GETNCNT returns the value of semncnt {READ}.
GETNCNT = 3
// GETPID returns the value of sempid {READ}
GETPID = 4
// GETVAL returns the value of semval {READ}
GETVAL = 5
// GETALL returns semvals into arg.array {READ}
GETALL = 6
// GETZCNT returns the value of semzcnt {READ}
GETZCNT = 7
// SETVAL sets the value of semval to arg.val {ALTER}
SETVAL = 8
// SETALL sets semvals from arg.array {ALTER}
SETALL = 9
)

23
sem_linux.go Normal file
View File

@ -0,0 +1,23 @@
// Copyright (c) 2020 Meng Huang (mhboy@outlook.com)
// This package is licensed under a MIT license that can be found in the LICENSE file.
// +build linux
package sem
const (
// GETNCNT returns the value of semncnt {READ}.
GETNCNT = 14
// GETPID returns the value of sempid {READ}
GETPID = 11
// GETVAL returns the value of semval {READ}
GETVAL = 12
// GETALL returns semvals into arg.array {READ}
GETALL = 13
// GETZCNT returns the value of semzcnt {READ}
GETZCNT = 15
// SETVAL sets the value of semval to arg.val {ALTER}
SETVAL = 16
// SETALL sets semvals from arg.array {ALTER}
SETALL = 17
)

View File

@ -1,6 +1,8 @@
// Copyright (c) 2020 Meng Huang (mhboy@outlook.com)
// This package is licensed under a MIT license that can be found in the LICENSE file.
// +build darwin linux dragonfly freebsd netbsd openbsd
package sem
import (
@ -18,21 +20,6 @@ const (
// IPC_NOWAIT returns error no wait.
IPC_NOWAIT = 04000
// GETNCNT returns the value of semncnt {READ}.
GETNCNT = 3
// GETPID returns the value of sempid {READ}
GETPID = 4
// GETVAL returns the value of semval {READ}
GETVAL = 5
// GETALL returns semvals into arg.array {READ}
GETALL = 6
// GETZCNT returns the value of semzcnt {READ}
GETZCNT = 7
// SETVAL sets the value of semval to arg.val {ALTER}
SETVAL = 8
// SETALL sets semvals from arg.array {ALTER}
SETALL = 9
// SEM_UNDO sets up adjust on exit entry
SEM_UNDO = 010000
@ -54,7 +41,7 @@ type sembuf struct {
func Get(key int) (uintptr, error) {
semid, _, _ := syscall.Syscall(syscall.SYS_SEMGET, uintptr(key), 1, 0666)
if int(semid) < 0 {
semid, _, err := syscall.Syscall(syscall.SYS_SEMGET, uintptr(key), 1, IPC_CREAT|IPC_EXCL|00600)
semid, _, err := syscall.Syscall(syscall.SYS_SEMGET, uintptr(key), 1, IPC_CREAT|IPC_EXCL|0666)
if int(semid) < 0 {
return 0, err
}