LEFT | RIGHT |
(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 "type.h" | 7 #include "type.h" |
8 #include "race.h" | 8 #include "race.h" |
9 #include "malloc.h" | 9 #include "malloc.h" |
10 | 10 |
(...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 | 1207 |
1208 chosen = (intgo)(uintptr)selectgo(&sel); | 1208 chosen = (intgo)(uintptr)selectgo(&sel); |
1209 if(rcase[chosen].dir == SelectRecv && rcase[chosen].typ->elem->size > si
zeof(void*)) | 1209 if(rcase[chosen].dir == SelectRecv && rcase[chosen].typ->elem->size > si
zeof(void*)) |
1210 word = (uintptr)recvptr; | 1210 word = (uintptr)recvptr; |
1211 | 1211 |
1212 FLUSH(&chosen); | 1212 FLUSH(&chosen); |
1213 FLUSH(&word); | 1213 FLUSH(&word); |
1214 FLUSH(&recvOK); | 1214 FLUSH(&recvOK); |
1215 } | 1215 } |
1216 | 1216 |
| 1217 static void closechan(Hchan *c, void *pc); |
| 1218 |
1217 // closechan(sel *byte); | 1219 // closechan(sel *byte); |
1218 #pragma textflag 7 | 1220 #pragma textflag 7 |
1219 void | 1221 void |
1220 runtime·closechan(Hchan *c) | 1222 runtime·closechan(Hchan *c) |
| 1223 { |
| 1224 closechan(c, runtime·getcallerpc(&c)); |
| 1225 } |
| 1226 |
| 1227 // For reflect |
| 1228 // func chanclose(c chan) |
| 1229 #pragma textflag 7 |
| 1230 void |
| 1231 reflect·chanclose(Hchan *c) |
| 1232 { |
| 1233 closechan(c, runtime·getcallerpc(&c)); |
| 1234 } |
| 1235 |
| 1236 static void |
| 1237 closechan(Hchan *c, void *pc) |
1221 { | 1238 { |
1222 SudoG *sg; | 1239 SudoG *sg; |
1223 G* gp; | 1240 G* gp; |
1224 | 1241 |
1225 if(c == nil) | 1242 if(c == nil) |
1226 runtime·panicstring("close of nil channel"); | 1243 runtime·panicstring("close of nil channel"); |
1227 | 1244 |
1228 if(runtime·gcwaiting) | 1245 if(runtime·gcwaiting) |
1229 runtime·gosched(); | 1246 runtime·gosched(); |
1230 | 1247 |
1231 runtime·lock(c); | 1248 runtime·lock(c); |
1232 if(c->closed) { | 1249 if(c->closed) { |
1233 runtime·unlock(c); | 1250 runtime·unlock(c); |
1234 runtime·panicstring("close of closed channel"); | 1251 runtime·panicstring("close of closed channel"); |
1235 } | 1252 } |
1236 | 1253 |
1237 if(raceenabled) { | 1254 if(raceenabled) { |
1238 » » runtime·racewritepc(c, runtime·getcallerpc(&c), runtime·closecha
n); | 1255 » » runtime·racewritepc(c, pc, runtime·closechan); |
1239 runtime·racerelease(c); | 1256 runtime·racerelease(c); |
1240 } | 1257 } |
1241 | 1258 |
1242 c->closed = true; | 1259 c->closed = true; |
1243 | 1260 |
1244 // release all readers | 1261 // release all readers |
1245 for(;;) { | 1262 for(;;) { |
1246 sg = dequeue(&c->recvq); | 1263 sg = dequeue(&c->recvq); |
1247 if(sg == nil) | 1264 if(sg == nil) |
1248 break; | 1265 break; |
1249 gp = sg->g; | 1266 gp = sg->g; |
1250 gp->param = nil; | 1267 gp->param = nil; |
1251 runtime·ready(gp); | 1268 runtime·ready(gp); |
1252 } | 1269 } |
1253 | 1270 |
1254 // release all writers | 1271 // release all writers |
1255 for(;;) { | 1272 for(;;) { |
1256 sg = dequeue(&c->sendq); | 1273 sg = dequeue(&c->sendq); |
1257 if(sg == nil) | 1274 if(sg == nil) |
1258 break; | 1275 break; |
1259 gp = sg->g; | 1276 gp = sg->g; |
1260 gp->param = nil; | 1277 gp->param = nil; |
1261 runtime·ready(gp); | 1278 runtime·ready(gp); |
1262 } | 1279 } |
1263 | 1280 |
1264 runtime·unlock(c); | 1281 runtime·unlock(c); |
1265 } | 1282 } |
1266 | 1283 |
1267 // For reflect | 1284 // For reflect |
1268 // func chanclose(c chan) | |
1269 void | |
1270 reflect·chanclose(Hchan *c) | |
1271 { | |
1272 runtime·closechan(c); | |
1273 } | |
1274 | |
1275 // For reflect | |
1276 // func chanlen(c chan) (len int) | 1285 // func chanlen(c chan) (len int) |
1277 void | 1286 void |
1278 reflect·chanlen(Hchan *c, intgo len) | 1287 reflect·chanlen(Hchan *c, intgo len) |
1279 { | 1288 { |
1280 if(c == nil) | 1289 if(c == nil) |
1281 len = 0; | 1290 len = 0; |
1282 else | 1291 else |
1283 len = c->qcount; | 1292 len = c->qcount; |
1284 FLUSH(&len); | 1293 FLUSH(&len); |
1285 } | 1294 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1348 } | 1357 } |
1349 | 1358 |
1350 static void | 1359 static void |
1351 racesync(Hchan *c, SudoG *sg) | 1360 racesync(Hchan *c, SudoG *sg) |
1352 { | 1361 { |
1353 runtime·racerelease(chanbuf(c, 0)); | 1362 runtime·racerelease(chanbuf(c, 0)); |
1354 runtime·raceacquireg(sg->g, chanbuf(c, 0)); | 1363 runtime·raceacquireg(sg->g, chanbuf(c, 0)); |
1355 runtime·racereleaseg(sg->g, chanbuf(c, 0)); | 1364 runtime·racereleaseg(sg->g, chanbuf(c, 0)); |
1356 runtime·raceacquire(chanbuf(c, 0)); | 1365 runtime·raceacquire(chanbuf(c, 0)); |
1357 } | 1366 } |
LEFT | RIGHT |