Daily bump.
[official-gcc.git] / libgo / go / runtime / os_aix.go
blob943cd2205d1754612483deb366141d772a21f0bb
1 // Copyright 2018 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 //go:build aix
7 package runtime
9 import (
10 "unsafe"
13 //extern sysconf
14 func sysconf(int32) _C_long
16 type mOS struct {
17 waitsema uintptr // semaphore for parking on locks
20 func getProcID() uint64 {
21 return uint64(gettid())
24 //extern malloc
25 func libc_malloc(uintptr) unsafe.Pointer
27 //go:noescape
28 //extern sem_init
29 func sem_init(sem *semt, pshared int32, value uint32) int32
31 //go:noescape
32 //extern sem_wait
33 func sem_wait(sem *semt) int32
35 //go:noescape
36 //extern sem_post
37 func sem_post(sem *semt) int32
39 //go:noescape
40 //extern sem_timedwait
41 func sem_timedwait(sem *semt, timeout *timespec) int32
43 //go:noescape
44 //extern clock_gettime
45 func clock_gettime(clock_id int64, timeout *timespec) int32
47 //go:nosplit
48 func semacreate(mp *m) {
49 if mp.waitsema != 0 {
50 return
53 var sem *semt
55 // Call libc's malloc rather than malloc. This will
56 // allocate space on the C heap. We can't call malloc
57 // here because it could cause a deadlock.
58 sem = (*semt)(libc_malloc(unsafe.Sizeof(*sem)))
59 if sem_init(sem, 0, 0) != 0 {
60 throw("sem_init")
62 mp.waitsema = uintptr(unsafe.Pointer(sem))
65 //go:nosplit
66 func semasleep(ns int64) int32 {
67 mp := getg().m
68 if ns >= 0 {
69 var ts timespec
71 if clock_gettime(_CLOCK_REALTIME, &ts) != 0 {
72 throw("clock_gettime")
75 sec := int64(ts.tv_sec) + ns/1e9
76 nsec := int64(ts.tv_nsec) + ns%1e9
77 if nsec >= 1e9 {
78 sec++
79 nsec -= 1e9
81 if sec != int64(timespec_sec_t(sec)) {
82 // Handle overflows (timespec_sec_t is 32-bit in 32-bit applications)
83 sec = 1<<31 - 1
85 ts.tv_sec = timespec_sec_t(sec)
86 ts.tv_nsec = timespec_nsec_t(nsec)
88 if sem_timedwait((*semt)(unsafe.Pointer(mp.waitsema)), &ts) != 0 {
89 err := errno()
90 if err == _ETIMEDOUT || err == _EAGAIN || err == _EINTR {
91 return -1
93 println("sem_timedwait err ", err, " ts.tv_sec ", ts.tv_sec, " ts.tv_nsec ", ts.tv_nsec, " ns ", ns, " id ", mp.id)
94 throw("sem_timedwait")
96 return 0
98 for {
99 r1 := sem_wait((*semt)(unsafe.Pointer(mp.waitsema)))
100 if r1 == 0 {
101 break
103 if errno() == _EINTR {
104 continue
106 throw("sem_wait")
108 return 0
111 //go:nosplit
112 func semawakeup(mp *m) {
113 if sem_post((*semt)(unsafe.Pointer(mp.waitsema))) != 0 {
114 throw("sem_post")
118 func osinit() {
119 ncpu = int32(sysconf(__SC_NPROCESSORS_ONLN))
120 physPageSize = uintptr(sysconf(__SC_PAGE_SIZE))
123 func setProcessCPUProfiler(hz int32) {
124 setProcessCPUProfilerTimer(hz)
127 func setThreadCPUProfiler(hz int32) {
128 setThreadCPUProfilerHz(hz)
131 //go:nosplit
132 func validSIGPROF(mp *m, c *sigctxt) bool {
133 return true
136 const (
137 _CLOCK_REALTIME = 9
138 _CLOCK_MONOTONIC = 10