|
|
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: PStype ps;
16: struct pt *ptptr;
17: int seq;
18: int msg;
19: struct ptnode *nxtnode;
20:
21: disable(ps);
22: if ( isbadport(portid) ||
23: #ifdef MEMMARK
24: unmarked(ptmark) ||
25: #endif
26: (ptptr= &ports[portid])->ptstate != PTALLOC ) {
27: restore(ps);
28: return(SYSERR);
29: }
30:
31: /* wait for message and verify that the port is still allocated */
32:
33: seq = ptptr->ptseq;
34: if (wait(ptptr->ptrsem) == SYSERR || ptptr->ptstate != PTALLOC
35: || ptptr->ptseq != seq) {
36: restore(ps);
37: return(SYSERR);
38: }
39:
40: /* dequeue first message that is waiting in the port */
41:
42: nxtnode = ptptr->pthead;
43: msg = nxtnode->ptmsg;
44: if (ptptr->pthead == ptptr->pttail) /* delete last item */
45: ptptr->pthead = ptptr->pttail = (struct ptnode *) NULL;
46: else
47: ptptr->pthead = nxtnode->ptnext;
48: nxtnode->ptnext = ptfree; /* return to free list */
49: ptfree = nxtnode;
50: signal(ptptr->ptssem);
51: restore(ps);
52: return(msg);
53: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.