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