1 // Copyright 2009 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.
18 func unimplemented(name
string) {
19 println(name
, "not implemented")
20 *(*int)(unsafe
.Pointer(uintptr(1231))) = 1231
24 func semacreate(mp
*m
) {
29 if err
:= pthread_mutex_init(&mp
.mutex
, nil); err
!= 0 {
30 throw("pthread_mutex_init")
32 if err
:= pthread_cond_init(&mp
.cond
, nil); err
!= 0 {
33 throw("pthread_cond_init")
38 func semasleep(ns
int64) int32 {
44 pthread_mutex_lock(&mp
.mutex
)
48 pthread_mutex_unlock(&mp
.mutex
)
52 spent
:= nanotime() - start
54 pthread_mutex_unlock(&mp
.mutex
)
59 err
:= pthread_cond_timedwait_relative_np(&mp
.cond
, &mp
.mutex
, &t
)
60 if err
== _ETIMEDOUT
{
61 pthread_mutex_unlock(&mp
.mutex
)
65 pthread_cond_wait(&mp
.cond
, &mp
.mutex
)
71 func semawakeup(mp
*m
) {
72 pthread_mutex_lock(&mp
.mutex
)
75 pthread_cond_signal(&mp
.cond
)
77 pthread_mutex_unlock(&mp
.mutex
)
80 // The read and write file descriptors used by the sigNote functions.
81 var sigNoteRead
, sigNoteWrite
int32
83 // sigNoteSetup initializes an async-signal-safe note.
85 // The current implementation of notes on Darwin is not async-signal-safe,
86 // because the functions pthread_mutex_lock, pthread_cond_signal, and
87 // pthread_mutex_unlock, called by semawakeup, are not async-signal-safe.
88 // There is only one case where we need to wake up a note from a signal
89 // handler: the sigsend function. The signal handler code does not require
90 // all the features of notes: it does not need to do a timed wait.
91 // This is a separate implementation of notes, based on a pipe, that does
92 // not support timed waits but is async-signal-safe.
93 func sigNoteSetup(*note
) {
94 if sigNoteRead
!= 0 || sigNoteWrite
!= 0 {
95 throw("duplicate sigNoteSetup")
98 sigNoteRead
, sigNoteWrite
, errno
= pipe()
102 closeonexec(sigNoteRead
)
103 closeonexec(sigNoteWrite
)
105 // Make the write end of the pipe non-blocking, so that if the pipe
106 // buffer is somehow full we will not block in the signal handler.
107 // Leave the read end of the pipe blocking so that we will block
109 setNonblock(sigNoteWrite
)
112 // sigNoteWakeup wakes up a thread sleeping on a note created by sigNoteSetup.
113 func sigNoteWakeup(*note
) {
115 write(uintptr(sigNoteWrite
), unsafe
.Pointer(&b
), 1)
118 // sigNoteSleep waits for a note created by sigNoteSetup to be woken.
119 func sigNoteSleep(*note
) {
123 n
:= read(sigNoteRead
, unsafe
.Pointer(&b
), 1)
131 // BSD interface for threading.
133 // pthread_create delayed until end of goenvs so that we
134 // can look at the environment first.
137 physPageSize
= getPageSize()
141 func validSIGPROF(mp
*m
, c
*sigctxt
) bool {