Guardian Programmer's Guide

Table Of Contents
Fault-Tolerant Programming in C
Guardian Programmer’s Guide 421922-014
27 - 45
Primary and Backup Processing
/* open $RECEIVE */
error = FILE_OPEN_ (RECEIVE_FILENAME,
(short) strlen (RECEIVE_FILENAME),
&receive_filenum,
/*access*/,
/*exclusion*/,
/*nowait*/,
1 /*receive depth*/);
/*Monitor the primary process processor. The backup receives
a message if the primary process goes down*/
MONITORCPUS ((unsigned short)(0x8000 >> primary_cpu ()));
/*Infinite loop that receives and processes messages*/
for (;;)
{
/*Read the next message from $RECEIVE with the intention
of replying*/
cond_code = READUPDATEX (receive_filenum,
(char *) &message,
(short) sizeof (message_format),
&countread);
/*Check process handle of sender of incoming message*/
FILE_GETRECEIVEINFO_ ((short *) &receive_info);
error = PROCESS_GETPAIRINFO_ (, , , , primary_phandle)
if (PROCESSHANDLE_COMPARE_ (primary_phandle,
(short *) &receiveinfo.z_sender) != 2
&& memcmp (&receiveinfo.z_sender,
null_phandle, PHANDLESIZE*2) != 0)
{ /*Message is not from primary process or system*/
REPLYX ( , , , , FEOWNERSHIP);
message.msgnumber = IGNORE_MESSAGE; }
else
/*Acknowledge that message was received*/
REPLYX ( , , , , 0);
/*Process message based on message number*/
switch (message.msgnumber)
{
case CPU_DOWN:
case PROCESS_DELETION:
/*Backup process takes over as primary*/