1 // Copyright 2019 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.
5 // This file is derived from os_aix.go.
12 func sysconf(int32) _C_long
15 func getPageSize() int32
18 waitsema
uintptr // semaphore for parking on locks
21 func getProcID() uint64 {
22 return uint64(gettid())
26 func libc_malloc(uintptr) unsafe
.Pointer
30 func sem_init(sem
*semt
, pshared
int32, value
uint32) int32
34 func sem_wait(sem
*semt
) int32
38 func sem_post(sem
*semt
) int32
41 //extern sem_timedwait
42 func sem_timedwait(sem
*semt
, timeout
*timespec
) int32
45 //extern clock_gettime
46 func clock_gettime(clock_id
int32, timeout
*timespec
) int32
49 func semacreate(mp
*m
) {
56 // Call libc's malloc rather than malloc. This will
57 // allocate space on the C heap. We can't call malloc
58 // here because it could cause a deadlock.
59 sem
= (*semt
)(libc_malloc(unsafe
.Sizeof(*sem
)))
60 if sem_init(sem
, 0, 0) != 0 {
63 mp
.waitsema
= uintptr(unsafe
.Pointer(sem
))
67 func semasleep(ns
int64) int32 {
72 if clock_gettime(_CLOCK_REALTIME
, &ts
) != 0 {
73 throw("clock_gettime")
76 sec
:= int64(ts
.tv_sec
) + ns
/1e9
77 nsec
:= int64(ts
.tv_nsec
) + ns%1e9
82 if sec
!= int64(timespec_sec_t(sec
)) {
83 // Handle overflows (timespec_sec_t is 32-bit in 32-bit applications)
86 ts
.tv_sec
= timespec_sec_t(sec
)
87 ts
.tv_nsec
= timespec_nsec_t(nsec
)
89 if sem_timedwait((*semt
)(unsafe
.Pointer(_m_
.waitsema
)), &ts
) != 0 {
91 if err
== _ETIMEDOUT || err
== _EAGAIN || err
== _EINTR
{
94 throw("sem_timedwait")
99 r1
:= sem_wait((*semt
)(unsafe
.Pointer(_m_
.waitsema
)))
103 if errno() == _EINTR
{
112 func semawakeup(mp
*m
) {
113 if sem_post((*semt
)(unsafe
.Pointer(mp
.waitsema
))) != 0 {
118 func getncpu() int32 {
119 n
:= int32(sysconf(__SC_NPROCESSORS_ONLN
))
128 if physPageSize
== 0 {
129 physPageSize
= uintptr(getPageSize())
133 func setProcessCPUProfiler(hz
int32) {
134 setProcessCPUProfilerTimer(hz
)
137 func setThreadCPUProfiler(hz
int32) {
138 setThreadCPUProfilerHz(hz
)
142 func validSIGPROF(mp
*m
, c
*sigctxt
) bool {