rs6000, update effective target for tests builtins-10*.c and vec_perm-runnable-i128.c
[official-gcc.git] / libgo / go / runtime / os_hurd.go
blob9750a4822cfafac2c14294e7874ca670f976eebf
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.
7 package runtime
9 import "unsafe"
11 //extern sysconf
12 func sysconf(int32) _C_long
14 //extern getpagesize
15 func getPageSize() int32
17 type mOS struct {
18 waitsema uintptr // semaphore for parking on locks
21 func getProcID() uint64 {
22 return uint64(gettid())
25 //extern malloc
26 func libc_malloc(uintptr) unsafe.Pointer
28 //go:noescape
29 //extern sem_init
30 func sem_init(sem *semt, pshared int32, value uint32) int32
32 //go:noescape
33 //extern sem_wait
34 func sem_wait(sem *semt) int32
36 //go:noescape
37 //extern sem_post
38 func sem_post(sem *semt) int32
40 //go:noescape
41 //extern sem_timedwait
42 func sem_timedwait(sem *semt, timeout *timespec) int32
44 //go:noescape
45 //extern clock_gettime
46 func clock_gettime(clock_id int32, timeout *timespec) int32
48 //go:nosplit
49 func semacreate(mp *m) {
50 if mp.waitsema != 0 {
51 return
54 var sem *semt
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 {
61 throw("sem_init")
63 mp.waitsema = uintptr(unsafe.Pointer(sem))
66 //go:nosplit
67 func semasleep(ns int64) int32 {
68 _m_ := getg().m
69 if ns >= 0 {
70 var ts timespec
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
78 if nsec >= 1e9 {
79 sec++
80 nsec -= 1e9
82 if sec != int64(timespec_sec_t(sec)) {
83 // Handle overflows (timespec_sec_t is 32-bit in 32-bit applications)
84 sec = 1<<31 - 1
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 {
90 err := errno()
91 if err == _ETIMEDOUT || err == _EAGAIN || err == _EINTR {
92 return -1
94 throw("sem_timedwait")
96 return 0
98 for {
99 r1 := sem_wait((*semt)(unsafe.Pointer(_m_.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 getncpu() int32 {
119 n := int32(sysconf(__SC_NPROCESSORS_ONLN))
120 if n < 1 {
121 return 1
123 return n
126 func osinit() {
127 ncpu = getncpu()
128 if physPageSize == 0 {
129 physPageSize = uintptr(getPageSize())
133 func setProcessCPUProfiler(hz int32) {
134 setProcessCPUProfilerTimer(hz)
137 func setThreadCPUProfiler(hz int32) {
138 setThreadCPUProfilerHz(hz)
141 //go:nosplit
142 func validSIGPROF(mp *m, c *sigctxt) bool {
143 return true