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
13 func sigismember(mask *sigset, i int) bool {
14 clear := *mask
15 sigdelset(&clear, i)
16 return clear != *mask
17 }
18
19 func Sigisblocked(i int) bool {
20 var sigmask sigset
21 sigprocmask(_SIG_SETMASK, nil, &sigmask)
22 return sigismember(&sigmask, i)
23 }
24
25 type M = m
26
27 var waitForSigusr1 struct {
28 rdpipe int32
29 wrpipe int32
30 mID int64
31 }
32
33
34
35
36
37
38
39
40
41 func WaitForSigusr1(r, w int32, ready func(mp *M)) (int64, int64) {
42 lockOSThread()
43
44 unblocksig(_SIGUSR1)
45
46 waitForSigusr1.rdpipe = r
47 waitForSigusr1.wrpipe = w
48
49 mp := getg().m
50 testSigusr1 = waitForSigusr1Callback
51 ready(mp)
52
53
54
55 entersyscallblock()
56 var b byte
57 read(waitForSigusr1.rdpipe, noescape(unsafe.Pointer(&b)), 1)
58 exitsyscall()
59
60 gotM := waitForSigusr1.mID
61 testSigusr1 = nil
62
63 unlockOSThread()
64
65 if b != 0 {
66
67 return -1, -1
68 }
69 return mp.id, gotM
70 }
71
72
73
74
75
76
77 func waitForSigusr1Callback(gp *g) bool {
78 if gp == nil || gp.m == nil {
79 waitForSigusr1.mID = -1
80 } else {
81 waitForSigusr1.mID = gp.m.id
82 }
83 b := byte(0)
84 write(uintptr(waitForSigusr1.wrpipe), noescape(unsafe.Pointer(&b)), 1)
85 return true
86 }
87
88
89 func SendSigusr1(mp *M) {
90 signalM(mp, _SIGUSR1)
91 }
92
93 const (
94 O_WRONLY = _O_WRONLY
95 O_CREAT = _O_CREAT
96 O_TRUNC = _O_TRUNC
97 )
98
View as plain text