Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(19)

Delta Between Two Patch Sets: src/pkg/runtime/proc.c

Issue 5714049: code review 5714049: runtime: run init on main thread (Closed)
Left Patch Set: Created 13 years, 1 month ago
Right Patch Set: diff -r d9b20dc0a595 https://go.googlecode.com/hg/ Created 13 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/runtime/mheap.c ('k') | src/pkg/runtime/runtime_linux_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 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 #include "runtime.h" 5 #include "runtime.h"
6 #include "arch_GOARCH.h" 6 #include "arch_GOARCH.h"
7 #include "defs_GOOS_GOARCH.h" 7 #include "defs_GOOS_GOARCH.h"
8 #include "malloc.h" 8 #include "malloc.h"
9 #include "os_GOOS.h" 9 #include "os_GOOS.h"
10 #include "stack.h" 10 #include "stack.h"
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 } 202 }
203 setmcpumax(runtime·gomaxprocs); 203 setmcpumax(runtime·gomaxprocs);
204 runtime·singleproc = runtime·gomaxprocs == 1; 204 runtime·singleproc = runtime·gomaxprocs == 1;
205 205
206 canaddmcpu(); // mcpu++ to account for bootstrap m 206 canaddmcpu(); // mcpu++ to account for bootstrap m
207 m->helpgc = 1; // flag to tell schedule() to mcpu-- 207 m->helpgc = 1; // flag to tell schedule() to mcpu--
208 runtime·sched.grunning++; 208 runtime·sched.grunning++;
209 209
210 mstats.enablegc = 1; 210 mstats.enablegc = 1;
211 m->nomemprof--; 211 m->nomemprof--;
212
213 scvg = runtime·newproc1((byte*)runtime·MHeap_Scavenger, nil, 0, 0, runti me·schedinit);
214 } 212 }
215 213
216 extern void main·init(void); 214 extern void main·init(void);
217 extern void main·main(void); 215 extern void main·main(void);
218 216
219 // The main goroutine. 217 // The main goroutine.
220 void 218 void
221 runtime·main(void) 219 runtime·main(void)
222 { 220 {
223 // Lock the main goroutine onto this, the main OS thread, 221 // Lock the main goroutine onto this, the main OS thread,
224 // during initialization. Most programs won't care, but a few 222 // during initialization. Most programs won't care, but a few
225 // do require certain calls to be made by the main thread. 223 // do require certain calls to be made by the main thread.
226 // Those can arrange for main.main to run in the main thread 224 // Those can arrange for main.main to run in the main thread
227 // by calling runtime.LockOSThread during initialization 225 // by calling runtime.LockOSThread during initialization
228 // to preserve the lock. 226 // to preserve the lock.
229 runtime·LockOSThread(); 227 runtime·LockOSThread();
230 runtime·sched.init = true; 228 runtime·sched.init = true;
229 scvg = runtime·newproc1((byte*)runtime·MHeap_Scavenger, nil, 0, 0, runti me·main);
231 main·init(); 230 main·init();
232 runtime·sched.init = false; 231 runtime·sched.init = false;
233 if(!runtime·sched.lockmain) 232 if(!runtime·sched.lockmain)
234 runtime·UnlockOSThread(); 233 runtime·UnlockOSThread();
235 234
236 main·main(); 235 main·main();
237 runtime·exit(0); 236 runtime·exit(0);
238 for(;;) 237 for(;;)
239 *(int32*)runtime·main = 0; 238 *(int32*)runtime·main = 0;
240 } 239 }
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 // We hold the sched lock, so no one else is manipulating the 579 // We hold the sched lock, so no one else is manipulating the
581 // g queue or changing mcpumax. Entersyscall can decrement 580 // g queue or changing mcpumax. Entersyscall can decrement
582 // mcpu, but if does so when there is something on the g queue, 581 // mcpu, but if does so when there is something on the g queue,
583 // the gwait bit will be set, so entersyscall will take the slow path 582 // the gwait bit will be set, so entersyscall will take the slow path
584 // and use the sched lock. So it cannot invalidate our decision . 583 // and use the sched lock. So it cannot invalidate our decision .
585 // 584 //
586 // Wait on global m queue. 585 // Wait on global m queue.
587 mput(m); 586 mput(m);
588 } 587 }
589 588
590 » // Look for deadlock situation: one single active g which happens to be scvg. 589 » // Look for deadlock situation.
591 » if(runtime·sched.grunning == 1 && runtime·sched.gwait == 0) { 590 » if((scvg == nil && runtime·sched.grunning == 0) ||
592 » » if(scvg->status == Grunning || scvg->status == Gsyscall) 591 » (scvg != nil && runtime·sched.grunning == 1 && runtime·sched.gwait == 0 &&
593 » » » runtime·throw("all goroutines are asleep - deadlock!"); 592 » (scvg->status == Grunning || scvg->status == Gsyscall))) {
593 » » runtime·throw("all goroutines are asleep - deadlock!");
594 } 594 }
595 595
596 m->nextg = nil; 596 m->nextg = nil;
597 m->waitnextg = 1; 597 m->waitnextg = 1;
598 runtime·noteclear(&m->havenextg); 598 runtime·noteclear(&m->havenextg);
599 599
600 // Stoptheworld is waiting for all but its cpu to go to stop. 600 // Stoptheworld is waiting for all but its cpu to go to stop.
601 // Entersyscall might have decremented mcpu too, but if so 601 // Entersyscall might have decremented mcpu too, but if so
602 // it will see the waitstop and take the slow path. 602 // it will see the waitstop and take the slow path.
603 // Exitsyscall never increments mcpu beyond mcpumax. 603 // Exitsyscall never increments mcpu beyond mcpumax.
(...skipping 1162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1766 arg[0][k.len] = 0; 1766 arg[0][k.len] = 0;
1767 1767
1768 arg[1] = runtime·malloc(v.len + 1); 1768 arg[1] = runtime·malloc(v.len + 1);
1769 runtime·memmove(arg[1], v.str, v.len); 1769 runtime·memmove(arg[1], v.str, v.len);
1770 arg[1][v.len] = 0; 1770 arg[1][v.len] = 0;
1771 1771
1772 runtime·asmcgocall((void*)libcgo_setenv, arg); 1772 runtime·asmcgocall((void*)libcgo_setenv, arg);
1773 runtime·free(arg[0]); 1773 runtime·free(arg[0]);
1774 runtime·free(arg[1]); 1774 runtime·free(arg[1]);
1775 } 1775 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b