Commit dec248c6 authored by Ken Thompson's avatar Ken Thompson

change channel read to clear

data just read from the channel.
this will make it easier to
recognize when to garbage
collect and finalize.

R=rsc
CC=golang-dev
https://golang.org/cl/882043
parent caa149f7
...@@ -300,6 +300,7 @@ loop: ...@@ -300,6 +300,7 @@ loop:
sg = dequeue(&c->sendq, c); sg = dequeue(&c->sendq, c);
if(sg != nil) { if(sg != nil) {
c->elemalg->copy(c->elemsize, ep, sg->elem); c->elemalg->copy(c->elemsize, ep, sg->elem);
c->elemalg->copy(c->elemsize, sg->elem, nil);
gp = sg->g; gp = sg->g;
gp->param = sg; gp->param = sg;
...@@ -331,6 +332,7 @@ loop: ...@@ -331,6 +332,7 @@ loop:
goto loop; goto loop;
c->elemalg->copy(c->elemsize, ep, sg->elem); c->elemalg->copy(c->elemsize, ep, sg->elem);
c->elemalg->copy(c->elemsize, sg->elem, nil);
freesg(c, sg); freesg(c, sg);
unlock(c); unlock(c);
return; return;
...@@ -356,6 +358,7 @@ asynch: ...@@ -356,6 +358,7 @@ asynch:
goto asynch; goto asynch;
} }
c->elemalg->copy(c->elemsize, ep, c->recvdataq->elem); c->elemalg->copy(c->elemsize, ep, c->recvdataq->elem);
c->elemalg->copy(c->elemsize, c->recvdataq->elem, nil);
c->recvdataq = c->recvdataq->link; c->recvdataq = c->recvdataq->link;
c->qcount--; c->qcount--;
sg = dequeue(&c->sendq, c); sg = dequeue(&c->sendq, c);
...@@ -778,8 +781,10 @@ loop: ...@@ -778,8 +781,10 @@ loop:
sel, c, cas, cas->send, o); sel, c, cas, cas->send, o);
if(!cas->send) { if(!cas->send) {
if(cas->u.elemp != nil) if(cas->u.elemp != nil) {
c->elemalg->copy(c->elemsize, cas->u.elemp, sg->elem); c->elemalg->copy(c->elemsize, cas->u.elemp, sg->elem);
c->elemalg->copy(c->elemsize, sg->elem, nil);
}
} }
freesg(c, sg); freesg(c, sg);
...@@ -787,8 +792,10 @@ loop: ...@@ -787,8 +792,10 @@ loop:
asyncrecv: asyncrecv:
// can receive from buffer // can receive from buffer
if(cas->u.elemp != nil) if(cas->u.elemp != nil) {
c->elemalg->copy(c->elemsize, cas->u.elemp, c->recvdataq->elem); c->elemalg->copy(c->elemsize, cas->u.elemp, c->recvdataq->elem);
c->elemalg->copy(c->elemsize, c->recvdataq->elem, nil);
}
c->recvdataq = c->recvdataq->link; c->recvdataq = c->recvdataq->link;
c->qcount--; c->qcount--;
sg = dequeue(&c->sendq, c); sg = dequeue(&c->sendq, c);
...@@ -817,8 +824,10 @@ syncrecv: ...@@ -817,8 +824,10 @@ syncrecv:
// can receive from sleeping sender (sg) // can receive from sleeping sender (sg)
if(debug) if(debug)
printf("syncrecv: sel=%p c=%p o=%d\n", sel, c, o); printf("syncrecv: sel=%p c=%p o=%d\n", sel, c, o);
if(cas->u.elemp != nil) if(cas->u.elemp != nil) {
c->elemalg->copy(c->elemsize, cas->u.elemp, sg->elem); c->elemalg->copy(c->elemsize, cas->u.elemp, sg->elem);
c->elemalg->copy(c->elemsize, sg->elem, nil);
}
gp = sg->g; gp = sg->g;
gp->param = sg; gp->param = sg;
ready(gp); ready(gp);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment