/* a->op is Recv: 从对应得Channel的发送队列随机取出一个Alt, 并读取数据,Alt对应的Task可以进入就绪队列了 a->op is Send: 将数据拷贝到Buffer中 */ static void altexec(Alt *a) { int i; Altarray *ar; Alt *other; Channel *c; c = a->c; ar = chanarray(c, otherop(a->op)); if(ar && ar->n){ // 这里的逻辑目前看都是a->op == RECV才跑得到 i = rand()%ar->n; other = ar->a[i]; // a->v = other->v altcopy(a, other); // 将other从Channel的队列(接收队列)中删除 altalldequeue(other->xalt); other->xalt[0].xalt = other; // Task重新进入就绪队列 taskready(other->task); }else { // 将a->v的数据放到buffer里面 altcopy(a, nil); } }
static void altexec(Alt *a) { int i; Altarray *ar; Alt *other; Channel *c; c = a->c; ar = chanarray(c, otherop(a->op)); if(ar && ar->n){ i = rand()%ar->n; other = ar->a[i]; altcopy(a, other); altalldequeue(other->xalt); other->xalt[0].xalt = other; taskready(other->task); }else altcopy(a, nil); }