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.
11 var NonblockingPipe = nonblockingPipe
13 var Closeonexec = closeonexec
15 func sigismember(mask *sigset, i int) bool {
21 func Sigisblocked(i int) bool {
23 sigprocmask(_SIG_SETMASK, nil, &sigmask)
24 return sigismember(&sigmask, i)
29 var waitForSigusr1 struct {
35 // WaitForSigusr1 blocks until a SIGUSR1 is received. It calls ready
36 // when it is set up to receive SIGUSR1. The ready function should
37 // cause a SIGUSR1 to be sent. The r and w arguments are a pipe that
38 // the signal handler can use to report when the signal is received.
40 // Once SIGUSR1 is received, it returns the ID of the current M and
41 // the ID of the M the SIGUSR1 was received on. If the caller writes
42 // a non-zero byte to w, WaitForSigusr1 returns immediately with -1, -1.
43 func WaitForSigusr1(r, w int32, ready func(mp *M)) (int64, int64) {
45 // Make sure we can receive SIGUSR1.
48 waitForSigusr1.rdpipe = r
49 waitForSigusr1.wrpipe = w
52 testSigusr1 = waitForSigusr1Callback
55 // Wait for the signal. We use a pipe rather than a note
56 // because write is always async-signal-safe.
59 read(waitForSigusr1.rdpipe, noescape(unsafe.Pointer(&b)), 1)
62 gotM := waitForSigusr1.mID
68 // timeout signal from caller
74 // waitForSigusr1Callback is called from the signal handler during
75 // WaitForSigusr1. It must not have write barriers because there may
78 //go:nowritebarrierrec
79 func waitForSigusr1Callback(gp *g) bool {
80 if gp == nil || gp.m == nil {
81 waitForSigusr1.mID = -1
83 waitForSigusr1.mID = gp.m.id
86 write(uintptr(waitForSigusr1.wrpipe), noescape(unsafe.Pointer(&b)), 1)
90 // SendSigusr1 sends SIGUSR1 to mp.
91 func SendSigusr1(mp *M) {