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.
5 // +build aix darwin dragonfly freebsd hurd linux netbsd openbsd solaris
11 var NonblockingPipe = nonblockingPipe
13 var SetNonblock = setNonblock
14 var Closeonexec = closeonexec
16 func sigismember(mask *sigset, i int) bool {
22 func Sigisblocked(i int) bool {
24 sigprocmask(_SIG_SETMASK, nil, &sigmask)
25 return sigismember(&sigmask, i)
30 var waitForSigusr1 struct {
36 // WaitForSigusr1 blocks until a SIGUSR1 is received. It calls ready
37 // when it is set up to receive SIGUSR1. The ready function should
38 // cause a SIGUSR1 to be sent. The r and w arguments are a pipe that
39 // the signal handler can use to report when the signal is received.
41 // Once SIGUSR1 is received, it returns the ID of the current M and
42 // the ID of the M the SIGUSR1 was received on. If the caller writes
43 // a non-zero byte to w, WaitForSigusr1 returns immediately with -1, -1.
44 func WaitForSigusr1(r, w int32, ready func(mp *M)) (int64, int64) {
46 // Make sure we can receive SIGUSR1.
49 waitForSigusr1.rdpipe = r
50 waitForSigusr1.wrpipe = w
53 testSigusr1 = waitForSigusr1Callback
56 // Wait for the signal. We use a pipe rather than a note
57 // because write is always async-signal-safe.
60 read(waitForSigusr1.rdpipe, noescape(unsafe.Pointer(&b)), 1)
63 gotM := waitForSigusr1.mID
69 // timeout signal from caller
75 // waitForSigusr1Callback is called from the signal handler during
76 // WaitForSigusr1. It must not have write barriers because there may
79 //go:nowritebarrierrec
80 func waitForSigusr1Callback(gp *g) bool {
81 if gp == nil || gp.m == nil {
82 waitForSigusr1.mID = -1
84 waitForSigusr1.mID = gp.m.id
87 write(uintptr(waitForSigusr1.wrpipe), noescape(unsafe.Pointer(&b)), 1)
91 // SendSigusr1 sends SIGUSR1 to mp.
92 func SendSigusr1(mp *M) {