Guardian Programmer's Guide

Table Of Contents
Synchronizing Processes
Guardian Programmer’s Guide 421922-014
26 - 9
Binary Semaphore Interface Declarations
BINSEM_OPEN_. These handles can be represented either as a structure or as an
array[10] of short int. Guardian procedures declared in CEXTDECS use the
array form. Some interfaces use a NSK_PHandle structure type, defined in the
kphandl.h header file. The kbinsem.h file can work either way.
By default, kbinsem.h uses the structure. Thus a program could contain:
#include <kbinsem.h>
NSK_PHandle myPhandle;
...
ret = PROCESSHANDLE_GETMINE((short*)&myPhandle);
...
ret = BINSEM_GETSTATS_(&myPhandle, ...);
or
#include <kbinsem.h>
short myPhandle[10];
...
ret = PROCESSHANDLE_GETMINE(myPhandle);
...
ret = BINSEM_GETSTATS_((NSK_Phandle*)myPhandle, ...);
Alternatively, to use the array form, the program could contain:
#include <CEXTDECS> /* or #define PHANDLE_IS_STRUCT 0 */
#include <kbinsem.h>
short myPhandle[10];
...
ret = PROCESSHANDLE_GETMINE(myPhandle);
...
ret = BINSEM_GETSTATS_(myPhandle, ...);
By using macros defined in kbinsem.h, source code can be made agnostic with
respect to the process handle type:
binSemPhanDef(myPhandle);
...
ret = PROCESSHANDLE_GETMINE(binSemPHanShortPtr myPhandle);
...
ret = BINSEM_GETSTATS_(binSemPhanPtr myPhandle, ...);
The declarations in kbinsem.h and those in CEXTDECS are compatible under either
of the following circumstances:
The CEXTDECS file is not included whole, and the BINSEM_OPEN_ section is
not included. By default, kbinsem.h defines PHANDLE_IS_STRUCT as 1 and
uses the structure pointer type.
The CEXTDECS file is included whole, before the kbinsem.h file. In this case,
kbinsem.h defines PHANDLE_IS_STRUCT as 0 and uses the array
representation.
For details, see the kbinsem.h header file.