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 package runtime | 5 package runtime |
6 #include "runtime.h" | 6 #include "runtime.h" |
7 #include "arch_GOARCH.h" | 7 #include "arch_GOARCH.h" |
8 #include "type.h" | 8 #include "type.h" |
9 #include "race.h" | 9 #include "race.h" |
10 #include "malloc.h" | 10 #include "malloc.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 runtime·park(nil, nil, "chan send (nil chan)"); | 89 runtime·park(nil, nil, "chan send (nil chan)"); |
90 return false; // not reached | 90 return false; // not reached |
91 } | 91 } |
92 | 92 |
93 if(debug) { | 93 if(debug) { |
94 runtime·printf("chansend: chan=%p; elem=", c); | 94 runtime·printf("chansend: chan=%p; elem=", c); |
95 c->elemtype->alg->print(c->elemsize, ep); | 95 c->elemtype->alg->print(c->elemsize, ep); |
96 runtime·prints("\n"); | 96 runtime·prints("\n"); |
97 } | 97 } |
98 | 98 |
| 99 if(raceenabled) |
| 100 runtime·racereadpc(c, pc, chansend); |
| 101 |
| 102 // Fast path: if it's a non-blocking operation that can't proceed, |
| 103 // then we can return w/o acquiring the lock. |
| 104 if(!block && !c->closed && ((c->dataqsiz == 0 && c->recvq.first == nil)
|| |
| 105 (c->dataqsiz > 0 && c->qcount == c->dataqsiz))) |
| 106 return false; |
| 107 |
99 t0 = 0; | 108 t0 = 0; |
100 mysg.releasetime = 0; | 109 mysg.releasetime = 0; |
101 if(runtime·blockprofilerate > 0) { | 110 if(runtime·blockprofilerate > 0) { |
102 t0 = runtime·cputicks(); | 111 t0 = runtime·cputicks(); |
103 mysg.releasetime = -1; | 112 mysg.releasetime = -1; |
104 } | 113 } |
105 | 114 |
106 runtime·lock(c); | 115 runtime·lock(c); |
107 if(raceenabled) | |
108 runtime·racereadpc(c, pc, chansend); | |
109 if(c->closed) | 116 if(c->closed) |
110 goto closed; | 117 goto closed; |
111 | 118 |
112 if(c->dataqsiz > 0) | 119 if(c->dataqsiz > 0) |
113 goto asynch; | 120 goto asynch; |
114 | 121 |
115 sg = dequeue(&c->recvq); | 122 sg = dequeue(&c->recvq); |
116 if(sg != nil) { | 123 if(sg != nil) { |
117 if(raceenabled) | 124 if(raceenabled) |
118 racesync(c, sg); | 125 racesync(c, sg); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 runtime·printf("chanrecv: chan=%p\n", c); | 222 runtime·printf("chanrecv: chan=%p\n", c); |
216 | 223 |
217 if(c == nil) { | 224 if(c == nil) { |
218 USED(t); | 225 USED(t); |
219 if(!block) | 226 if(!block) |
220 return false; | 227 return false; |
221 runtime·park(nil, nil, "chan receive (nil chan)"); | 228 runtime·park(nil, nil, "chan receive (nil chan)"); |
222 return false; // not reached | 229 return false; // not reached |
223 } | 230 } |
224 | 231 |
| 232 // Fast path: if it's a non-blocking operation that can't proceed, |
| 233 // then we can return w/o acquiring the lock. |
| 234 if(!block && !c->closed && ((c->dataqsiz == 0 && c->sendq.first == nil)
|| |
| 235 (c->dataqsiz > 0 && c->qcount == 0))) |
| 236 return false; |
| 237 |
225 t0 = 0; | 238 t0 = 0; |
226 mysg.releasetime = 0; | 239 mysg.releasetime = 0; |
227 if(runtime·blockprofilerate > 0) { | 240 if(runtime·blockprofilerate > 0) { |
228 t0 = runtime·cputicks(); | 241 t0 = runtime·cputicks(); |
229 mysg.releasetime = -1; | 242 mysg.releasetime = -1; |
230 } | 243 } |
231 | 244 |
232 runtime·lock(c); | 245 runtime·lock(c); |
233 if(c->dataqsiz > 0) | 246 if(c->dataqsiz > 0) |
234 goto asynch; | 247 goto asynch; |
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1146 } | 1159 } |
1147 | 1160 |
1148 static void | 1161 static void |
1149 racesync(Hchan *c, SudoG *sg) | 1162 racesync(Hchan *c, SudoG *sg) |
1150 { | 1163 { |
1151 runtime·racerelease(chanbuf(c, 0)); | 1164 runtime·racerelease(chanbuf(c, 0)); |
1152 runtime·raceacquireg(sg->g, chanbuf(c, 0)); | 1165 runtime·raceacquireg(sg->g, chanbuf(c, 0)); |
1153 runtime·racereleaseg(sg->g, chanbuf(c, 0)); | 1166 runtime·racereleaseg(sg->g, chanbuf(c, 0)); |
1154 runtime·raceacquire(chanbuf(c, 0)); | 1167 runtime·raceacquire(chanbuf(c, 0)); |
1155 } | 1168 } |
OLD | NEW |