Source file
src/runtime/sigqueue_plan9.go
Documentation: runtime
1
2
3
4
5
6
7 package runtime
8
9 import _ "unsafe"
10
11 const qsize = 64
12
13 var sig struct {
14 q noteQueue
15 inuse bool
16
17 lock mutex
18 note note
19 sleeping bool
20 }
21
22 type noteData struct {
23 s [_ERRMAX]byte
24 n int
25 }
26
27 type noteQueue struct {
28 lock mutex
29 data [qsize]noteData
30 ri int
31 wi int
32 full bool
33 }
34
35
36 func (q *noteQueue) push(item *byte) bool {
37 lock(&q.lock)
38 if q.full {
39 unlock(&q.lock)
40 return false
41 }
42 s := gostringnocopy(item)
43 copy(q.data[q.wi].s[:], s)
44 q.data[q.wi].n = len(s)
45 q.wi++
46 if q.wi == qsize {
47 q.wi = 0
48 }
49 if q.wi == q.ri {
50 q.full = true
51 }
52 unlock(&q.lock)
53 return true
54 }
55
56 func (q *noteQueue) pop() string {
57 lock(&q.lock)
58 q.full = false
59 if q.ri == q.wi {
60 unlock(&q.lock)
61 return ""
62 }
63 note := &q.data[q.ri]
64 item := string(note.s[:note.n])
65 q.ri++
66 if q.ri == qsize {
67 q.ri = 0
68 }
69 unlock(&q.lock)
70 return item
71 }
72
73
74
75 func sendNote(s *byte) bool {
76 if !sig.inuse {
77 return false
78 }
79
80
81 if !sig.q.push(s) {
82 return false
83 }
84
85 lock(&sig.lock)
86 if sig.sleeping {
87 sig.sleeping = false
88 notewakeup(&sig.note)
89 }
90 unlock(&sig.lock)
91
92 return true
93 }
94
95
96
97
98
99 func sigRecvPrepareForFixup() {
100 }
101
102
103
104
105 func signal_recv() string {
106 for {
107 note := sig.q.pop()
108 if note != "" {
109 return note
110 }
111
112 lock(&sig.lock)
113 sig.sleeping = true
114 noteclear(&sig.note)
115 unlock(&sig.lock)
116 notetsleepg(&sig.note, -1)
117 }
118 }
119
120
121
122
123
124
125
126
127
128 func signalWaitUntilIdle() {
129 for {
130 lock(&sig.lock)
131 sleeping := sig.sleeping
132 unlock(&sig.lock)
133 if sleeping {
134 return
135 }
136 Gosched()
137 }
138 }
139
140
141
142 func signal_enable(s uint32) {
143 if !sig.inuse {
144
145 sig.inuse = true
146 noteclear(&sig.note)
147 }
148 }
149
150
151
152 func signal_disable(s uint32) {
153 }
154
155
156
157 func signal_ignore(s uint32) {
158 }
159
160
161 func signal_ignored(s uint32) bool {
162 return false
163 }
164
View as plain text