Determining the Ownership of an Event

A process becomes the owner of an event when the process successfully procures that event, and remains the owner until the event is liberated. A process can use the MCP procedure EVENT_STATUS to determine whether that process is the current owner of the event.

The EVENT_STATUS procedure is primarily useful in fault-handling code, EPILOG procedures, and EXCEPTION procedures. In these contexts, the EVENT_STATUS result enables the process to determine whether it should liberate the event before exiting a procedure, to make the event available to other processes. For further information about EPILOG and EXCEPTION procedures, refer to Using EPILOG and EXCEPTION Procedures later in this section.

Note: The EVENT_STATUS procedure is the only safe method of determining the owner of an event. Unsafe NEWP programs that manipulate events directly should be avoided, because the format of events differs among system models and is subject to change without notice. Use of the EVENT_STATUS procedure makes it unnecessary to modify application programs when the event format changes.

The following declarations can be included in an ALGOL program to enable the EVENT_STATUS procedure to be used:

LIBRARY MCPSUPPORT (LIBACCESS = BYFUNCTION);

REAL PROCEDURE EVENT_STATUS(EV);
     EVENT EV;
     LIBRARY MCPSUPPORT;

DEFINE LOCKOWNERF = [42:39] #; % Lock owner field in EVENT_STATUS result

The program passes the event in question to the EV parameter of the EVENT_STATUS procedure. This procedure returns information about the event in the procedure result. The format of this result is as follows:

Field

Meaning

[42:39]

Stack numberof the process that owns this event

[3:2]

Event usage

0 = Normal event

2 = Interrupt attached

[1:1]

Availability state

0 = AVAILABLE

1 = NOT AVAILABLE

[00:01]

Happened state

0 = NOT HAPPENED

1 = HAPPENED

Note: The information in the EVENT_STATUS result reflects the state of the event at a single moment in time. If other processes have access to the event, ownership of the event could change between the time a process calls EVENT_STATUS and the time the process reads the result.

Assuming that EVENT_STATUS, the MCPSUPPORT library, and the LOCKOWNERF field have been declared as shown previously, the following ALGOL statement can be used to determine whether the current process owns an event:

IF PROCESSID = EVENT_STATUS(EVENT1).LOCKOWNERF THEN
BEGIN
   %  Take various appropriate actions
END;