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 "type.h" | 6 #include "type.h" |
7 | 7 |
8 #define MAXALIGN 7 | 8 #define MAXALIGN 7 |
9 #define NOSELGEN 1 | 9 #define NOSELGEN 1 |
10 | 10 |
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1015 runtime·printf("syncsend: sel=%p c=%p o=%d\n", sel, c, o); | 1015 runtime·printf("syncsend: sel=%p c=%p o=%d\n", sel, c, o); |
1016 if(sg->elem != nil) | 1016 if(sg->elem != nil) |
1017 c->elemalg->copy(c->elemsize, sg->elem, cas->sg.elem); | 1017 c->elemalg->copy(c->elemsize, sg->elem, cas->sg.elem); |
1018 gp = sg->g; | 1018 gp = sg->g; |
1019 gp->param = sg; | 1019 gp->param = sg; |
1020 runtime·ready(gp); | 1020 runtime·ready(gp); |
1021 | 1021 |
1022 retc: | 1022 retc: |
1023 // return to pc corresponding to chosen case | 1023 // return to pc corresponding to chosen case |
1024 pc = cas->pc; | 1024 pc = cas->pc; |
1025 » as = (byte*)selp + cas->so; | 1025 » if(cas->so > 0) { |
1026 » » as = (byte*)selp + cas->so; | |
1027 » » *as = true; | |
1028 » } | |
r
2012/09/05 15:07:04
what's this about?
rsc
2012/09/13 21:26:55
Done.
| |
1026 runtime·free(sel); | 1029 runtime·free(sel); |
1027 *as = true; | |
1028 return pc; | 1030 return pc; |
1029 | 1031 |
1030 sclose: | 1032 sclose: |
1031 // send on closed channel | 1033 // send on closed channel |
1032 selunlock(sel); | 1034 selunlock(sel); |
1033 runtime·panicstring("send on closed channel"); | 1035 runtime·panicstring("send on closed channel"); |
1034 return nil; // not reached | 1036 return nil; // not reached |
1035 } | 1037 } |
1036 | 1038 |
1039 typedef struct runtimeSelect runtimeSelect; | |
iant
2012/09/05 15:53:10
Add comment saying this struct must match reflect
rsc
2012/09/13 21:26:55
Done.
| |
1040 struct runtimeSelect | |
1041 { | |
1042 uintptr dir; | |
1043 ChanType *typ; | |
1044 Hchan *ch; | |
1045 uintptr val; | |
1046 }; | |
1047 | |
1048 // func rselect(cases []runtimeSelect) (chosen int, word uintptr, recvOK bool) | |
1049 void | |
1050 reflect·rselect(Slice cases, int32 chosen, uintptr word, bool recvOK) | |
1051 { | |
1052 int32 i; | |
1053 Select *sel; | |
1054 runtimeSelect* rcase, *rc; | |
1055 void *elem; | |
1056 void *recvptr; | |
1057 uintptr maxsize; | |
1058 | |
1059 chosen = -1; | |
1060 word = 0; | |
1061 recvOK = false; | |
1062 | |
1063 maxsize = 0; | |
1064 rcase = (runtimeSelect*)cases.array; | |
1065 for(i=0; i<cases.len; i++) { | |
1066 rc = &rcase[i]; | |
1067 if(rc->dir == RecvDir && maxsize < rc->typ->elem->size) | |
1068 maxsize = rc->typ->elem->size; | |
1069 } | |
1070 | |
1071 recvptr = nil; | |
1072 if(maxsize > sizeof(void*)) | |
1073 recvptr = runtime·mal(maxsize); | |
1074 | |
1075 newselect(cases.len, &sel); | |
1076 for(i=0; i<cases.len; i++) { | |
1077 rc = &rcase[i]; | |
1078 switch(rc->dir) { | |
1079 case 0: | |
1080 selectdefault(sel, (void*)i, 0); | |
1081 break; | |
1082 case SendDir: | |
1083 if(rc->typ->elem->size > sizeof(void*)) | |
1084 elem = (void*)rc->val; | |
1085 else | |
1086 elem = (void*)&rc->val; | |
1087 selectsend(sel, rc->ch, (void*)i, elem, 0); | |
1088 break; | |
1089 case RecvDir: | |
1090 if(rc->typ->elem->size > sizeof(void*)) | |
1091 elem = recvptr; | |
1092 else | |
1093 elem = &word; | |
1094 selectrecv(sel, rc->ch, (void*)i, elem, &recvOK, 0); | |
1095 break; | |
1096 } | |
1097 } | |
1098 | |
1099 chosen = (int32)(uintptr)selectgo(&sel); | |
1100 if(rcase[chosen].dir == RecvDir && rcase[chosen].typ->elem->size > sizeo f(void*)) | |
1101 word = (uintptr)recvptr; | |
1102 | |
1103 FLUSH(&chosen); | |
1104 FLUSH(&word); | |
1105 FLUSH(&recvOK); | |
1106 } | |
1107 | |
1037 // closechan(sel *byte); | 1108 // closechan(sel *byte); |
1038 void | 1109 void |
1039 runtime·closechan(Hchan *c) | 1110 runtime·closechan(Hchan *c) |
1040 { | 1111 { |
1041 SudoG *sg; | 1112 SudoG *sg; |
1042 G* gp; | 1113 G* gp; |
1043 | 1114 |
1044 if(c == nil) | 1115 if(c == nil) |
1045 runtime·panicstring("close of nil channel"); | 1116 runtime·panicstring("close of nil channel"); |
1046 | 1117 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1153 { | 1224 { |
1154 sgp->link = nil; | 1225 sgp->link = nil; |
1155 if(q->first == nil) { | 1226 if(q->first == nil) { |
1156 q->first = sgp; | 1227 q->first = sgp; |
1157 q->last = sgp; | 1228 q->last = sgp; |
1158 return; | 1229 return; |
1159 } | 1230 } |
1160 q->last->link = sgp; | 1231 q->last->link = sgp; |
1161 q->last = sgp; | 1232 q->last = sgp; |
1162 } | 1233 } |
OLD | NEW |