LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2014 The Go Authors. All rights reserved. | 1 // Copyright 2014 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package runtime | 5 package runtime |
6 | 6 |
7 import "unsafe" | 7 import "unsafe" |
8 | 8 |
9 func runtime_init() | 9 func runtime_init() |
10 func main_init() | 10 func main_init() |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 // Delicate dance: the semaphore implementation calls | 174 // Delicate dance: the semaphore implementation calls |
175 // acquireSudog, acquireSudog calls new(sudog), | 175 // acquireSudog, acquireSudog calls new(sudog), |
176 // new calls malloc, malloc can call the garbage collector, | 176 // new calls malloc, malloc can call the garbage collector, |
177 // and the garbage collector calls the semaphore implementation | 177 // and the garbage collector calls the semaphore implementation |
178 // in stoptheworld. | 178 // in stoptheworld. |
179 // Break the cycle by doing acquirem/releasem around new(sudog). | 179 // Break the cycle by doing acquirem/releasem around new(sudog). |
180 // The acquirem/releasem increments m.locks during new(sudog), | 180 // The acquirem/releasem increments m.locks during new(sudog), |
181 // which keeps the garbage collector from being invoked. | 181 // which keeps the garbage collector from being invoked. |
182 mp := acquirem() | 182 mp := acquirem() |
183 p := new(sudog) | 183 p := new(sudog) |
| 184 if p.elem != nil { |
| 185 gothrow("acquireSudog: found p.elem != nil after new") |
| 186 } |
184 releasem(mp) | 187 releasem(mp) |
185 return p | 188 return p |
186 } | 189 } |
187 | 190 |
188 //go:nosplit | 191 //go:nosplit |
189 func releaseSudog(s *sudog) { | 192 func releaseSudog(s *sudog) { |
190 if s.elem != nil { | 193 if s.elem != nil { |
191 gothrow("runtime: sudog with non-nil elem") | 194 gothrow("runtime: sudog with non-nil elem") |
192 } | 195 } |
193 if s.selectdone != nil { | 196 if s.selectdone != nil { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 if readgstatus(gp) == _Gidle { | 260 if readgstatus(gp) == _Gidle { |
258 gothrow("allgadd: bad status Gidle") | 261 gothrow("allgadd: bad status Gidle") |
259 } | 262 } |
260 | 263 |
261 lock(&allglock) | 264 lock(&allglock) |
262 allgs = append(allgs, gp) | 265 allgs = append(allgs, gp) |
263 allg = &allgs[0] | 266 allg = &allgs[0] |
264 allglen = uintptr(len(allgs)) | 267 allglen = uintptr(len(allgs)) |
265 unlock(&allglock) | 268 unlock(&allglock) |
266 } | 269 } |
LEFT | RIGHT |