Xinu7/contrib/ether.monitor/sys/recvtim.c
/* recvtim.c - recvtim */
#include <conf.h>
#include <kernel.h>
#include <proc.h>
#include <q.h>
#include <sleep.h>
/*------------------------------------------------------------------------
* recvtim - wait to receive a message or timeout and return result
*------------------------------------------------------------------------
*/
SYSCALL recvtim(maxwait)
int maxwait;
{
struct pentry *pptr;
int msg;
char ps;
disable(ps);
pptr = &proctab[currpid];
if ( !pptr->phasmsg ) { /* if no message, wait */
insertd(currpid, clockq, maxwait);
slnempty = TRUE;
sltop = & q[q[clockq].qnext].qkey;
pptr->pstate = PRTRECV;
resched();
}
if ( pptr->phasmsg ) {
msg = pptr->pmsg; /* msg. arrived => retrieve it */
pptr->phasmsg = FALSE;
} else { /* still no message => TIMEOUT */
msg = TIMEOUT;
}
restore(ps);
return(msg);
}