00001 00007 /* Embedded XINU, Copyright (C) 2007. All rights reserved. */ 00008 00009 #include <kernel.h> 00010 #include <device.h> 00011 #include <proc.h> 00012 00019 syscall receive(bool block) 00020 { 00021 irqmask ps; 00022 pcb *ppcb; 00023 ulong msg; 00024 00025 ps = disable(); 00026 ppcb = &proctab[currpid]; 00027 if ( !ppcb->hasmsg ) 00028 { 00029 if ( BLOCK == block ) /* if no message, block */ 00030 { 00031 ppcb->state = PRRECV; /* change state from PRCURR to PRRECV */ 00032 resched(); /* reschedule */ 00033 } 00034 else /* if no message, return NULL */ 00035 { 00036 restore(ps); 00037 return NULL; 00038 } 00039 } 00040 msg = ppcb->msg; /* retrieve message */ 00041 ppcb->hasmsg = FALSE; /* reset mailbox */ 00042 restore(ps); 00043 return msg; 00044 }