Message Passing Routines - Implementation

IPC Implementation in XINU

Corresponding to the simple IPC semantics, we have simple IPC implementation.

There are two PCB fields for message passing in XINU. These are phasmsg and pmsg. Phasmsg is a flag to indicate whether that process has a message waiting to be received in pmsg. Pmsg contains the waiting message (if there is one).

Send()

Send() first does the usual error checking (such as making sure that the destination process identified by pid is valid. Then it checks to make sure that there isn't already a message waiting for the destination process. If there is one waiting, it treats this as an error and returns SYSERR.

If all is well, the message is put in the pmsg field of the destination process' PCB and the phasmsg flag is set. It then checks to see if the destination process is blocked awaiting a message (in state PRRECV). If it is, the destination process is readied, and a context switch occurs (why? just in case the blocked receiving process is a higher priority process than the running one).

Receive()

Receive is simple. It checks its phasmsg flag to see if a message is waiting for it. If so, it clears the flag and returns the message. Otherwise, it needs to block itself, which it does with state PRRECV (receive-blocked process).

Recvclr()

Recvclr is even more simple still. Recvclr checks the phasmsg field to see if a message is waiting to be received. If so, the flag is cleared and the message is returned. If not, the value OK is returned.

1