pipid32 pipcreate(void) { intmask mask; /* saved interrupt mask */ pipid32 pipid; /* ID of newly created pipe */ struct pipent *piptr; /* ptr to pipe's table entry */ mask = disable(); /* saved interrupt mask */ pipid = pipnewid(); if (isbadpipid(pipid) || (piptr->pistate != PIPE_FREE)) { restore(mask); return (pipid32)SYSERR; } piptr = &piptab[pipid]; piptr->pistate = PIPE_USED; uint32 j; /* iterate through all buffer slots */ for (j = 0; j < PIPE_SIZ; j++) { /* initialize the buffer */ piptr->pipebuffer[j] = ' '; } //piptr->psem = semcreate(PIPE_SIZ); /* initialize producer sem */ //piptr->csem = semcreate(0); /* initialize consumer sem */ restore(mask); return pipid; }
syscall pipdelete( pipid32 pip ) { struct pipent *pipptr; intmask mask; mask = disable(); if(isbadpipid(pip)){ restore(mask); return (pipid32) (SYSERR); } pipptr = &piptab[pip]; if(pipptr->pipstate == PIPE_FREE){ restore(mask); return (pipid32) (SYSERR); } if(pipptr->pipOwner != getpid()){ restore(mask); return (pipid32) (SYSERR); } pipptr->pipstate = PIPE_FREE; memset(pipptr->buf, '\0', PIPE_SIZE); pipptr->pipOwner = -1; pipptr->pipReader = -1; pipptr->pipWriter = -1; pipptr->bufCharCount = -1; pipcount--; semdelete(pipptr->fullSem); semdelete(pipptr->emptySem); restore(mask); return OK; }
syscall pipdisconnect( pipid32 pipid /* ID of pipe to connect */ ) { intmask mask; /* saved interrupt mask */ struct pipent *piptr; /* ptr to pipe's table entry */ mask = disable(); /* saved interrupt mask */ if (isbadpipid(pipid) || (piptr->pistate != PIPE_CONNECTED)) { restore(mask); return SYSERR; } piptr = &piptab[pipid]; piptr->pistate = PIPE_USED; restore(mask); return pipid; }