Left: | ||
Right: |
OLD | NEW |
---|---|
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 "malloc.h" | 7 #include "malloc.h" |
8 #include "stack.h" | 8 #include "stack.h" |
9 #include "race.h" | 9 #include "race.h" |
10 #include "type.h" | 10 #include "type.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 static void gosched0(G*); | 103 static void gosched0(G*); |
104 static void goexit0(G*); | 104 static void goexit0(G*); |
105 static void gfput(P*, G*); | 105 static void gfput(P*, G*); |
106 static G* gfget(P*); | 106 static G* gfget(P*); |
107 static void gfpurge(P*); | 107 static void gfpurge(P*); |
108 static void globrunqput(G*); | 108 static void globrunqput(G*); |
109 static G* globrunqget(P*); | 109 static G* globrunqget(P*); |
110 static P* pidleget(void); | 110 static P* pidleget(void); |
111 static void pidleput(P*); | 111 static void pidleput(P*); |
112 static void injectglist(G*); | 112 static void injectglist(G*); |
113 static void preemptall(void); | |
114 static void preemptone(P*); | |
113 | 115 |
114 // The bootstrap sequence is: | 116 // The bootstrap sequence is: |
115 // | 117 // |
116 // call osinit | 118 // call osinit |
117 // call schedinit | 119 // call schedinit |
118 // make & queue new G | 120 // make & queue new G |
119 // call runtime·mstart | 121 // call runtime·mstart |
120 // | 122 // |
121 // The new G calls runtime·main. | 123 // The new G calls runtime·main. |
122 void | 124 void |
(...skipping 1935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2058 inclocked(-1); | 2060 inclocked(-1); |
2059 if(runtime·cas(&p->status, s, Pidle)) { | 2061 if(runtime·cas(&p->status, s, Pidle)) { |
2060 n++; | 2062 n++; |
2061 handoffp(p); | 2063 handoffp(p); |
2062 } | 2064 } |
2063 inclocked(1); | 2065 inclocked(1); |
2064 } | 2066 } |
2065 return n; | 2067 return n; |
2066 } | 2068 } |
2067 | 2069 |
2070 static void | |
2071 preemptall(void) | |
iant
2013/06/01 00:24:46
Please add a comment before these new functions ex
| |
2072 { | |
2073 P *p; | |
2074 int32 i; | |
2075 | |
2076 for(i = 0; i < runtime·gomaxprocs; i++) { | |
2077 p = runtime·allp[i]; | |
2078 if(p == nil || p->status != Prunning) | |
2079 continue; | |
2080 preemptone(p); | |
2081 } | |
2082 } | |
2083 | |
2084 static void | |
2085 preemptone(P *p) | |
2086 { | |
2087 M *mp; | |
2088 G *gp; | |
2089 | |
2090 mp = p->m; | |
2091 if(mp == nil || mp == m) | |
2092 return; | |
2093 gp = mp->curg; | |
2094 if(gp == nil || gp == mp->g0) | |
2095 return; | |
2096 gp->stackguard = StackPreempt; | |
iant
2013/06/01 00:24:46
If I understand this correctly, this g might actua
| |
2097 } | |
2098 | |
2068 // Put mp on midle list. | 2099 // Put mp on midle list. |
2069 // Sched must be locked. | 2100 // Sched must be locked. |
2070 static void | 2101 static void |
2071 mput(M *mp) | 2102 mput(M *mp) |
2072 { | 2103 { |
2073 mp->schedlink = runtime·sched.midle; | 2104 mp->schedlink = runtime·sched.midle; |
2074 runtime·sched.midle = mp; | 2105 runtime·sched.midle = mp; |
2075 runtime·sched.nmidle++; | 2106 runtime·sched.nmidle++; |
2076 checkdead(); | 2107 checkdead(); |
2077 } | 2108 } |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2362 } | 2393 } |
2363 } | 2394 } |
2364 if(s != i/2 && s != i/2+1) { | 2395 if(s != i/2 && s != i/2+1) { |
2365 runtime·printf("bad steal %d, want %d or %d, iter %d\n", | 2396 runtime·printf("bad steal %d, want %d or %d, iter %d\n", |
2366 s, i/2, i/2+1, i); | 2397 s, i/2, i/2+1, i); |
2367 runtime·throw("bad steal"); | 2398 runtime·throw("bad steal"); |
2368 } | 2399 } |
2369 } | 2400 } |
2370 } | 2401 } |
2371 | 2402 |
OLD | NEW |