Guardian Programmer's Guide

Table Of Contents
Fault-Tolerant Programming in C
Guardian Programmer’s Guide 421922-014
27 - 41
Updating State Information
Function primary_cpu
This function returns the CPU number of the primary process CPU.
/*This function returns the processor number of the primary
process processor*/
short primary_cpu (void)
{
short cpu;
short error;
/*Get the primary process phandle*/
error = PROCESS_GETPAIRINFO_ (/*current process*/,
/*pair:maxlen*/,,
/*pairlen*/,
primary_phandle);
/*Get and return the primary process processor*/
error = PROCESSHANDLE_DECOMPOSE_ (primary_phandle,
&cpu);
return cpu;
}
Updating State Information
After the primary process performs its initialization tasks, it begins executing the main
processing loop. Code is added to the main processing loop to update state
information in the backup process. The state information includes control state and
application state; file state is not needed because the program does no I/O. The value
of the loop counter provides control state and application state: it tells the backup
process where to resume execution, and it is the data needed to continue application
processing. File state information for the stdout file is updated.
The code to update state information is written as a separate function, named
update_backup, which is called by the primary process.
Function backup_exists
Function backup_exists tests for the existence of the backup process by calling
PROCESS_GETPAIRINFO_. If the backup does exist, the function returns -1. This
function is called by update_backup to make sure that the backup process exists
before updating state information.
short backup_exists (void)
{
short null_phandle [PHANDLESIZE] = NULLPHANDLE;
short error;