Source file
src/runtime/export_unix_test.go
1
2
3
4
5
6
7 package runtime
8
9 import "unsafe"
10
11 var NonblockingPipe = nonblockingPipe
12 var SetNonblock = setNonblock
13 var Closeonexec = closeonexec
14
15 func sigismember(mask *sigset, i int) bool {
16 clear := *mask
17 sigdelset(&clear, i)
18 return clear != *mask
19 }
20
21 func Sigisblocked(i int) bool {
22 var sigmask sigset
23 sigprocmask(_SIG_SETMASK, nil, &sigmask)
24 return sigismember(&sigmask, i)
25 }
26
27 type M = m
28
29 var waitForSigusr1 struct {
30 rdpipe int32
31 wrpipe int32
32 mID int64
33 }
34
35
36
37
38
39
40
41
42
43 func WaitForSigusr1(r, w int32, ready func(mp *M)) (int64, int64) {
44 lockOSThread()
45
46 unblocksig(_SIGUSR1)
47
48 waitForSigusr1.rdpipe = r
49 waitForSigusr1.wrpipe = w
50
51 mp := getg().m
52 testSigusr1 = waitForSigusr1Callback
53 ready(mp)
54
55
56
57 entersyscallblock()
58 var b byte
59 read(waitForSigusr1.rdpipe, noescape(unsafe.Pointer(&b)), 1)
60 exitsyscall()
61
62 gotM := waitForSigusr1.mID
63 testSigusr1 = nil
64
65 unlockOSThread()
66
67 if b != 0 {
68
69 return -1, -1
70 }
71 return mp.id, gotM
72 }
73
74
75
76
77
78
79 func waitForSigusr1Callback(gp *g) bool {
80 if gp == nil || gp.m == nil {
81 waitForSigusr1.mID = -1
82 } else {
83 waitForSigusr1.mID = gp.m.id
84 }
85 b := byte(0)
86 write(uintptr(waitForSigusr1.wrpipe), noescape(unsafe.Pointer(&b)), 1)
87 return true
88 }
89
90
91 func SendSigusr1(mp *M) {
92 signalM(mp, _SIGUSR1)
93 }
94
View as plain text