|
|
1.1 root 1: /* preceive.c - preceive */
2:
3: #include <conf.h>
4: #include <kernel.h>
5: #include <mark.h>
6: #include <ports.h>
7:
8: /*------------------------------------------------------------------------
9: * preceive -- receive a message from a port, blocking if port empty
10: *------------------------------------------------------------------------
11: */
12: SYSCALL preceive(portid)
13: int portid;
14: {
15: struct pt *ptptr;
16: int seq;
1.1.1.2 ! root 17: WORD msg;
1.1 root 18: struct ptnode *nxtnode;
19:
1.1.1.2 ! root 20: #ifdef DEBUG
! 21: dotrace("preceive", &portid, 1);
! 22: #endif
! 23: disable();
1.1 root 24: if ( isbadport(portid) ||
25: #ifdef MEMMARK
26: unmarked(ptmark) ||
27: #endif
28: (ptptr= &ports[portid])->ptstate != PTALLOC ) {
1.1.1.2 ! root 29: restore();
1.1 root 30: return(SYSERR);
31: }
32:
33: /* wait for message and verify that the port is still allocated */
34:
35: seq = ptptr->ptseq;
36: if (wait(ptptr->ptrsem) == SYSERR || ptptr->ptstate != PTALLOC
37: || ptptr->ptseq != seq) {
1.1.1.2 ! root 38: restore();
1.1 root 39: return(SYSERR);
40: }
41:
42: /* dequeue first message that is waiting in the port */
43:
44: nxtnode = ptptr->pthead;
45: msg = nxtnode->ptmsg;
46: if (ptptr->pthead == ptptr->pttail) /* delete last item */
1.1.1.2 ! root 47: ptptr->pthead = ptptr->pttail = (struct ptnode *)NULL;
1.1 root 48: else
49: ptptr->pthead = nxtnode->ptnext;
50: nxtnode->ptnext = ptfree; /* return to free list */
51: ptfree = nxtnode;
52: signal(ptptr->ptssem);
1.1.1.2 ! root 53: restore();
1.1 root 54: return(msg);
55: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.