Skip to content

Commit 29b190f

Browse files
MatthieuSarterianlancetaylor
authored andcommitted
runtime: netpoll and semaphores for AIX
semaphore implementation based on Solaris implementation in libgo/go/runtime/os_solaris.go netpoll is just a stub to avoid build failure on AIX. Issue golang/go#19200 Change-Id: Iac0712e01ae6f5208852489d542a9cad41f6c50e Reviewed-on: https://go-review.googlesource.com/37966 Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent a0275c0 commit 29b190f

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed

libgo/go/runtime/netpoll_aix.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// Fake network poller for AIX
6+
// TODO : this is just stubs to allow building, implementation required
7+
8+
package runtime
9+
10+
func netpollinit() {
11+
}
12+
13+
func netpollopen(fd uintptr, pd *pollDesc) int32 {
14+
return 0
15+
}
16+
17+
func netpollclose(fd uintptr) int32 {
18+
return 0
19+
}
20+
21+
func netpollarm(pd *pollDesc, mode int) {
22+
}
23+
24+
func netpoll(block bool) *g {
25+
return nil
26+
}

libgo/go/runtime/os_aix.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package runtime
6+
7+
import "unsafe"
8+
9+
type mOS struct {
10+
waitsema uintptr // semaphore for parking on locks
11+
}
12+
13+
//extern malloc
14+
func libc_malloc(uintptr) unsafe.Pointer
15+
16+
//go:noescape
17+
//extern sem_init
18+
func sem_init(sem *semt, pshared int32, value uint32) int32
19+
20+
//go:noescape
21+
//extern sem_wait
22+
func sem_wait(sem *semt) int32
23+
24+
//go:noescape
25+
//extern sem_post
26+
func sem_post(sem *semt) int32
27+
28+
//go:noescape
29+
//extern sem_timedwait
30+
func sem_timedwait(sem *semt, timeout *timespec) int32
31+
32+
//go:noescape
33+
//extern clock_gettime
34+
func clock_gettime(clock_id int64, timeout *timespec) int32
35+
36+
//go:nosplit
37+
func semacreate(mp *m) {
38+
if mp.mos.waitsema != 0 {
39+
return
40+
}
41+
42+
var sem *semt
43+
44+
// Call libc's malloc rather than malloc. This will
45+
// allocate space on the C heap. We can't call malloc
46+
// here because it could cause a deadlock.
47+
sem = (*semt)(libc_malloc(unsafe.Sizeof(*sem)))
48+
if sem_init(sem, 0, 0) != 0 {
49+
throw("sem_init")
50+
}
51+
mp.mos.waitsema = uintptr(unsafe.Pointer(sem))
52+
}
53+
54+
//go:nosplit
55+
func semasleep(ns int64) int32 {
56+
_m_ := getg().m
57+
if ns >= 0 {
58+
const CLOCK_REALTIME int64 = 9
59+
var ts timespec
60+
61+
if clock_gettime(CLOCK_REALTIME, &ts) != 0 {
62+
throw("clock_gettime")
63+
}
64+
ts.tv_sec += timespec_sec_t(ns / 1000000000)
65+
ts.tv_nsec += timespec_nsec_t((int64(ts.tv_nsec) + ns) % 1000000000)
66+
if ts.tv_nsec >= 1000000000 {
67+
ts.tv_sec += timespec_sec_t(1)
68+
ts.tv_nsec -= timespec_nsec_t(1000000000)
69+
}
70+
71+
if sem_timedwait((*semt)(unsafe.Pointer(_m_.mos.waitsema)), &ts) != 0 {
72+
err := errno()
73+
if err == _ETIMEDOUT || err == _EAGAIN || err == _EINTR {
74+
return -1
75+
}
76+
throw("sem_timedwait")
77+
}
78+
return 0
79+
}
80+
for {
81+
r1 := sem_wait((*semt)(unsafe.Pointer(_m_.mos.waitsema)))
82+
if r1 == 0 {
83+
break
84+
}
85+
if errno() == _EINTR {
86+
continue
87+
}
88+
throw("sem_wait")
89+
}
90+
return 0
91+
}
92+
93+
//go:nosplit
94+
func semawakeup(mp *m) {
95+
if sem_post((*semt)(unsafe.Pointer(mp.mos.waitsema))) != 0 {
96+
throw("sem_post")
97+
}
98+
}

0 commit comments

Comments
 (0)