view src/sys_pipe_read.cbc @ 155:2c63276c6b04

tweak
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Thu, 19 Dec 2019 11:33:23 +0900
parents 343f8f3c8f18
children
line wrap: on
line source

#include "../context.h"
#interface "SysRead.h"

// ----
// typedef struct PipeRead<Type, Isa> impl SysRead {
//   struct pipe* p;
//   int i;
//   int n;
//   __code cbc_piperead1(Type* sys_read, struct pipe* p, __code next(...));
//   __code cbc_piperead2(Type* sys_read, int i, int n, struct pipe* p, __code next(...));
//   __code cbc_piperead3(Type* sys_read, int i, struct pipe* p, __code next(...));
//   __code next(...);
// } PipeRead;
// ----

SysRead* createPipeRead(struct Context* cbc_context) {
    struct SysRead* sys_read  = new SysRead();
    struct PipeRead* pipe_read = new PipeRead();
    sys_read->sys_read = (union Data*)pipe_read;
    pipe_read->p = NULL;
    pipe_read->i  = 0;
    pipe_read->n  = 0;
    sys_read->impl = NULL;
    sys_read->addr = NULL;
    sys_read->n  = 0;
    pipe_read->cbc_piperead1 = C_cbc_piperead1PipeRead;
    pipe_read->cbc_piperead2 = C_cbc_piperead2PipeRead;
    pipe_read->cbc_piperead3 = C_cbc_piperead3PipeRead;
    sys_read->read = C_readPipeRead;
    return sys_read;
}
__code cbc_piperead1PipeRead(struct PipeRead* sys_read, struct pipe* p, __code next(...)) {
    if (p->nread == p->nwrite && p->writeopen){
        if(proc->killed){
            release(&p->lock);
            goto err();
        }
        goto cbc_sleep(&p->nread, &p->lock, cbc_piperead1);
    }
    goto next(sys_read,0,sys_read->n,sys_read->p,cbc_piperead2SysReadImpl);
}

__code cbc_piperead2PipeRead(struct PipeRead* sys_read, int i, int n, struct pipe* p, __code next(...)) {
  if (i < n && !(p->nread == p->nwrite)) {
      addr[i] = p->data[p->nread++ % PIPESIZE];
      i ++;
      goto cbc_piperead2(sys_read,i,n,p,addr);
  }
  goto cbc_wakeup(&p->nwrite, cbc_piperead3);  //DOC: piperead-wakeup
}

__code cbc_piperead3PipeRead(struct PipeRead* sys_read, int i, struct pipe* p, __code next(...)) {

  goto next(...);
}


__code readPipeRead(struct PipeRead* sys_read, union Data* impl, char* addr, int n, __code next(int ret,...)) {

  goto next(int ret,...);
}