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:
parent
9d8b15138a
commit
6bc5630462
23
sem_bsd.go
Normal file
23
sem_bsd.go
Normal 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
23
sem_linux.go
Normal 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
|
||||||
|
)
|
19
sem_unix.go
19
sem_unix.go
@ -1,6 +1,8 @@
|
|||||||
// Copyright (c) 2020 Meng Huang (mhboy@outlook.com)
|
// Copyright (c) 2020 Meng Huang (mhboy@outlook.com)
|
||||||
// This package is licensed under a MIT license that can be found in the LICENSE file.
|
// 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
|
package sem
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -18,21 +20,6 @@ const (
|
|||||||
// IPC_NOWAIT returns error no wait.
|
// IPC_NOWAIT returns error no wait.
|
||||||
IPC_NOWAIT = 04000
|
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 sets up adjust on exit entry
|
||||||
SEM_UNDO = 010000
|
SEM_UNDO = 010000
|
||||||
|
|
||||||
@ -54,7 +41,7 @@ type sembuf struct {
|
|||||||
func Get(key int) (uintptr, error) {
|
func Get(key int) (uintptr, error) {
|
||||||
semid, _, _ := syscall.Syscall(syscall.SYS_SEMGET, uintptr(key), 1, 0666)
|
semid, _, _ := syscall.Syscall(syscall.SYS_SEMGET, uintptr(key), 1, 0666)
|
||||||
if int(semid) < 0 {
|
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 {
|
if int(semid) < 0 {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user