CedarProcess.mesa
Copyright Ó 1985, 1986, 1987, 1991 by Xerox Corporation. All rights reserved.
Russ Atkinson (RRA) January 19, 1987 6:58:12 pm PST
Types
Priority:
TYPE =
MACHINE
DEPENDENT {
This definition of Priority must be numerically the same as the one in the Process interface.
idle (0), -- not for client use; only Watch should use this priority
background (1), -- good for non-interactive CPU users
normal (2), -- good for most processes
foreground (3), -- good for important processes
excited (4), -- good for a few time-sensitive interactive processes
faultHandlers (5), -- not for client use
realTime (6), -- not normally for client use; normally for device control
swatWatcher (7) -- not for client use; used by emergency debugger call
};
ForkableProc:
TYPE =
PROC [data:
REF]
RETURNS [results:
REF ¬
NIL];
This type of procedure can be forked by the Fork operation. It takes the callback data and returns the results (if any) for the forked process.
ForkOptions:
TYPE =
RECORD [
priority: Priority ¬ normal,
The priority to use if usePriority = TRUE
usePriority:
BOOL ¬
FALSE,
IF FALSE, use the current priority
inheritProperties:
BOOL ¬
FALSE
IF TRUE, inherit the process properties (accessed through ProcessProps)
];
DefaultForkOptions: ForkOptions = [];
These options are used by Fork.
Status: TYPE = {done, aborted, debugging, busy, invalid};
Process: TYPE = REF ProcessRep;
ProcessList: TYPE = LIST OF Process;
ProcessRep:
TYPE =
RECORD [
process:
PROCESS ¬
NIL,
The current Mesa process behind this process. Not valid if status = done or status = aborted.
action: ForkableProc ¬
NIL,
The forked procedure for this process.
data:
REF ¬
NIL,
The call back data for this process.
results:
REF ¬
NIL,
The results (if any). Only valid if status = done.
status: Status ¬ busy,
The status of the process.
done => the action completed (returning results)
aborted => the action raised ERROR ABORTED
debugging => debugCount > 0
busy => the process is running (we hope)
debugCount:
INT ¬ 0,
increments when AMEvents.Debugging occurs
decrements when AMEvents.Debugged occurs
abortCount:
INT ¬ 0,
increments when Abort is called
abortRequested:
BOOL ¬
FALSE
set TRUE when Abort is called
set FALSE when CheckAbort is called
];
Operations for the current process
SetPriority:
PROC [priority: Priority];
Sets the priority of the current process to the given priority
GetPriority:
PROC
RETURNS [priority: Priority];
Gets the priority of the current process
DoWithPriority:
PROC [priority: Priority, action:
PROC];
Performs the action using the given priority. After the action completes the priority reverts to the priority before the call.
Operations for forked processes
Fork:
PROC [action: ForkableProc, data:
REF ¬
NIL, options: ForkOptions ¬ DefaultForkOptions]
RETURNS [Process];
Forks the action with the given callback data and the given options. Note that the action must NOT be a nested procedure.
GetStatus:
PROC [process: Process ¬
NIL]
RETURNS [Status];
(process = NIL => check self)
Monitored access to process.status.
Join:
PROC [process: Process, wait:
BOOL ¬
TRUE]
RETURNS [status: Status, results:
REF];
wait = TRUE AND (process.status = debugging OR process.status = busy) =>
wait for (process.status = done OR process.status = aborted)
In all other cases, return the current results and status.
Abort:
PROC [process: Process];
a monitored call to make process.abortRequested = TRUE
increments process.abortCount
CheckAbort:
PROC [process: Process ¬
NIL];
(process = NIL => check self)
a monitored call to make process.abortRequested = TRUE
raises ERROR ABORTED if process.abortRequested was TRUE when called
(OR if Process.CheckForAbort raises ABORTED)
}.