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

Side by Side Diff: src/pkg/runtime/chan.c

Issue 882043: code review 882043: change channel read to clear (Closed)
Patch Set: code review 882043: change channel read to clear Created 14 years, 12 months 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:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 static int32 debug = 0; 8 static int32 debug = 0;
9 9
10 enum 10 enum
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 loop: 293 loop:
294 if(c->dataqsiz > 0) 294 if(c->dataqsiz > 0)
295 goto asynch; 295 goto asynch;
296 296
297 if(c->closed & Wclosed) 297 if(c->closed & Wclosed)
298 goto closed; 298 goto closed;
299 299
300 sg = dequeue(&c->sendq, c); 300 sg = dequeue(&c->sendq, c);
301 if(sg != nil) { 301 if(sg != nil) {
302 c->elemalg->copy(c->elemsize, ep, sg->elem); 302 c->elemalg->copy(c->elemsize, ep, sg->elem);
303 c->elemalg->copy(c->elemsize, sg->elem, nil);
303 304
304 gp = sg->g; 305 gp = sg->g;
305 gp->param = sg; 306 gp->param = sg;
306 unlock(c); 307 unlock(c);
307 ready(gp); 308 ready(gp);
308 309
309 if(pres != nil) 310 if(pres != nil)
310 *pres = true; 311 *pres = true;
311 return; 312 return;
312 } 313 }
(...skipping 11 matching lines...) Expand all
324 enqueue(&c->recvq, sg); 325 enqueue(&c->recvq, sg);
325 unlock(c); 326 unlock(c);
326 gosched(); 327 gosched();
327 328
328 lock(c); 329 lock(c);
329 sg = g->param; 330 sg = g->param;
330 if(sg == nil) 331 if(sg == nil)
331 goto loop; 332 goto loop;
332 333
333 c->elemalg->copy(c->elemsize, ep, sg->elem); 334 c->elemalg->copy(c->elemsize, ep, sg->elem);
335 c->elemalg->copy(c->elemsize, sg->elem, nil);
334 freesg(c, sg); 336 freesg(c, sg);
335 unlock(c); 337 unlock(c);
336 return; 338 return;
337 339
338 asynch: 340 asynch:
339 if(c->qcount <= 0) { 341 if(c->qcount <= 0) {
340 if(c->closed & Wclosed) 342 if(c->closed & Wclosed)
341 goto closed; 343 goto closed;
342 344
343 if(pres != nil) { 345 if(pres != nil) {
344 unlock(c); 346 unlock(c);
345 c->elemalg->copy(c->elemsize, ep, nil); 347 c->elemalg->copy(c->elemsize, ep, nil);
346 *pres = false; 348 *pres = false;
347 return; 349 return;
348 } 350 }
349 sg = allocsg(c); 351 sg = allocsg(c);
350 g->status = Gwaiting; 352 g->status = Gwaiting;
351 enqueue(&c->recvq, sg); 353 enqueue(&c->recvq, sg);
352 unlock(c); 354 unlock(c);
353 gosched(); 355 gosched();
354 356
355 lock(c); 357 lock(c);
356 goto asynch; 358 goto asynch;
357 } 359 }
358 c->elemalg->copy(c->elemsize, ep, c->recvdataq->elem); 360 c->elemalg->copy(c->elemsize, ep, c->recvdataq->elem);
361 c->elemalg->copy(c->elemsize, c->recvdataq->elem, nil);
359 c->recvdataq = c->recvdataq->link; 362 c->recvdataq = c->recvdataq->link;
360 c->qcount--; 363 c->qcount--;
361 sg = dequeue(&c->sendq, c); 364 sg = dequeue(&c->sendq, c);
362 if(sg != nil) { 365 if(sg != nil) {
363 gp = sg->g; 366 gp = sg->g;
364 freesg(c, sg); 367 freesg(c, sg);
365 unlock(c); 368 unlock(c);
366 ready(gp); 369 ready(gp);
367 if(pres != nil) 370 if(pres != nil)
368 *pres = true; 371 *pres = true;
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 if(c->dataqsiz > 0) { 774 if(c->dataqsiz > 0) {
772 // prints("shouldnt happen\n"); 775 // prints("shouldnt happen\n");
773 goto loop; 776 goto loop;
774 } 777 }
775 778
776 if(debug) 779 if(debug)
777 printf("wait-return: sel=%p c=%p cas=%p send=%d o=%d\n", 780 printf("wait-return: sel=%p c=%p cas=%p send=%d o=%d\n",
778 sel, c, cas, cas->send, o); 781 sel, c, cas, cas->send, o);
779 782
780 if(!cas->send) { 783 if(!cas->send) {
781 » » if(cas->u.elemp != nil) 784 » » if(cas->u.elemp != nil) {
782 c->elemalg->copy(c->elemsize, cas->u.elemp, sg->elem); 785 c->elemalg->copy(c->elemsize, cas->u.elemp, sg->elem);
786 c->elemalg->copy(c->elemsize, sg->elem, nil);
787 }
783 } 788 }
784 789
785 freesg(c, sg); 790 freesg(c, sg);
786 goto retc; 791 goto retc;
787 792
788 asyncrecv: 793 asyncrecv:
789 // can receive from buffer 794 // can receive from buffer
790 » if(cas->u.elemp != nil) 795 » if(cas->u.elemp != nil) {
791 c->elemalg->copy(c->elemsize, cas->u.elemp, c->recvdataq->elem); 796 c->elemalg->copy(c->elemsize, cas->u.elemp, c->recvdataq->elem);
797 c->elemalg->copy(c->elemsize, c->recvdataq->elem, nil);
798 }
792 c->recvdataq = c->recvdataq->link; 799 c->recvdataq = c->recvdataq->link;
793 c->qcount--; 800 c->qcount--;
794 sg = dequeue(&c->sendq, c); 801 sg = dequeue(&c->sendq, c);
795 if(sg != nil) { 802 if(sg != nil) {
796 gp = sg->g; 803 gp = sg->g;
797 freesg(c, sg); 804 freesg(c, sg);
798 ready(gp); 805 ready(gp);
799 } 806 }
800 goto retc; 807 goto retc;
801 808
802 asyncsend: 809 asyncsend:
803 // can send to buffer 810 // can send to buffer
804 if(cas->u.elem != nil) 811 if(cas->u.elem != nil)
805 c->elemalg->copy(c->elemsize, c->senddataq->elem, cas->u.elem); 812 c->elemalg->copy(c->elemsize, c->senddataq->elem, cas->u.elem);
806 c->senddataq = c->senddataq->link; 813 c->senddataq = c->senddataq->link;
807 c->qcount++; 814 c->qcount++;
808 sg = dequeue(&c->recvq, c); 815 sg = dequeue(&c->recvq, c);
809 if(sg != nil) { 816 if(sg != nil) {
810 gp = sg->g; 817 gp = sg->g;
811 freesg(c, sg); 818 freesg(c, sg);
812 ready(gp); 819 ready(gp);
813 } 820 }
814 goto retc; 821 goto retc;
815 822
816 syncrecv: 823 syncrecv:
817 // can receive from sleeping sender (sg) 824 // can receive from sleeping sender (sg)
818 if(debug) 825 if(debug)
819 printf("syncrecv: sel=%p c=%p o=%d\n", sel, c, o); 826 printf("syncrecv: sel=%p c=%p o=%d\n", sel, c, o);
820 » if(cas->u.elemp != nil) 827 » if(cas->u.elemp != nil) {
821 c->elemalg->copy(c->elemsize, cas->u.elemp, sg->elem); 828 c->elemalg->copy(c->elemsize, cas->u.elemp, sg->elem);
829 c->elemalg->copy(c->elemsize, sg->elem, nil);
830 }
822 gp = sg->g; 831 gp = sg->g;
823 gp->param = sg; 832 gp->param = sg;
824 ready(gp); 833 ready(gp);
825 goto retc; 834 goto retc;
826 835
827 rclose: 836 rclose:
828 // read at end of closed channel 837 // read at end of closed channel
829 if(cas->u.elemp != nil) 838 if(cas->u.elemp != nil)
830 c->elemalg->copy(c->elemsize, cas->u.elemp, nil); 839 c->elemalg->copy(c->elemsize, cas->u.elemp, nil);
831 c->closed |= Rclosed; 840 c->closed |= Rclosed;
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 static uint32 1048 static uint32
1040 fastrand2(void) 1049 fastrand2(void)
1041 { 1050 {
1042 static uint32 x = 0x49f6428aUL; 1051 static uint32 x = 0x49f6428aUL;
1043 1052
1044 x += x; 1053 x += x;
1045 if(x & 0x80000000L) 1054 if(x & 0x80000000L)
1046 x ^= 0xfafd871bUL; 1055 x ^= 0xfafd871bUL;
1047 return x; 1056 return x;
1048 } 1057 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

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