ProcessImpl.mesa
Copyright Ó 1988, 1991, 1992 by Xerox Corporation. All rights reserved.
Carl Hauser, February 16, 1989 1:49:07 pm PST
Foote, May 31, 1991 11:17 am PDT
Michael Plass, March 12, 1992 11:33 am PST
DIRECTORY
Process,
RuntimeError;
ProcessImpl: CEDAR PROGRAM
IMPORTS RuntimeError
EXPORTS Process
~ BEGIN
Initializing monitors and condition variables
ConditionPointer: TYPE = Process.ConditionPointer;
MonitorPointer: TYPE = Process.MonitorPointer;
InitializeMonitor:
PUBLIC
PROC [monitor: MonitorPointer] = {
DoIt:
PROC [monitor: MonitorPointer] ~
TRUSTED
MACHINE
CODE {
"XR←InitializeMonitor"
};
DoIt[monitor];
};
InitializeCondition:
PUBLIC
PROC [condition: ConditionPointer, ticks: Ticks] = {
DoIt:
PROC [condition: ConditionPointer, ticks: Ticks] ~
TRUSTED
MACHINE
CODE {
"XR←InitializeCondition"
};
DoIt[condition, ticks];
};
Ticks
Ticks: TYPE = Process.Ticks;
Milliseconds: TYPE = Process.Milliseconds;
Seconds: TYPE = Process.Seconds;
MsecToTicks:
PUBLIC
PROC [ms: Milliseconds]
RETURNS [ticks: Ticks] = {
DoIt:
PROC [Milliseconds]
RETURNS [Ticks] ~
TRUSTED
MACHINE
CODE {
"XR←MsecToTicks"
};
ticks ¬ DoIt[ms];
};
SecondsToTicks:
PUBLIC
PROC [seconds: Seconds]
RETURNS [ticks: Ticks] ~ {
RETURN[MsecToTicks[1000*seconds]];
};
TicksToMsec:
PUBLIC
PROC [ticks: Ticks]
RETURNS [ms: Milliseconds] = {
DoIt:
PROC [Ticks]
RETURNS [Milliseconds] ~
TRUSTED
MACHINE
CODE {
"XR←TicksToMsec"
};
ms ¬ DoIt[ticks];
};
Timeouts
minTimeout: Ticks ¬ 1;
SetTimeout:
PUBLIC PROC [condition: ConditionPointer, ticks: Ticks]
= {
DoIt:
PROC [condition: ConditionPointer, ticks: Ticks] ~
TRUSTED
MACHINE
CODE {
"XR←SetTimeout"
};
ticks ¬ MAX[ticks, minTimeout];
DoIt[condition, ticks];
};
DisableTimeout:
PUBLIC PROC [condition:
ConditionPointer]
= {
DoIt:
PROC [condition: ConditionPointer] ~
TRUSTED
MACHINE
CODE {
"XR𡤍isableTimeout"
};
DoIt[condition];
};
Detaching processes
Detach:
PUBLIC PROC [p:
PROCESS] =
TRUSTED {
DoIt:
PROC [
POINTER TO PROCESS]
RETURNS [
INT]~
TRUSTED
MACHINE
CODE {
"XRtachCT"
};
IF DoIt[@p]#0 THEN ERROR InvalidProcess[p];
};
Identity of the currently executing process
GetCurrent:
PUBLIC
PROC
RETURNS [p:
PROCESS] =
TRUSTED {
DoIt:
PROC[
POINTER
TO
PROCESS] ~
TRUSTED
MACHINE
CODE {
"XR←GetCurrent"
};
DoIt[@p]
};
Priorities of processes
Priority: TYPE = Process.Priority;
SetPriority:
PUBLIC
PROC [p: Priority] ~ {
DoIt:
PROC [Priority] ~
TRUSTED
MACHINE
CODE {
"XR←SetPriority"
};
DoIt[p];
};
GetPriority:
PUBLIC PROC
RETURNS [Priority]
= {
DoIt:
PROC
RETURNS [Priority] ~
TRUSTED
MACHINE
CODE {
"XR←GetPriority"
};
RETURN[DoIt[]]
};
Aborts
Abort:
PUBLIC
PROC [p:
PROCESS] ~
TRUSTED {
DoIt:
PROC [
POINTER
TO
PROCESS]
RETURNS [
INT] ~
TRUSTED
MACHINE
CODE {
"XRortCT"
};
IF DoIt[@p]#0 THEN ERROR InvalidProcess[p];
};
Requests that the indicated process be aborted.
CancelAbort:
PUBLIC
PROC [p:
PROCESS] ~
TRUSTED {
DoIt:
PROC [
POINTER
TO
PROCESS]
RETURNS [
INT] ~
TRUSTED
MACHINE
CODE {
"XRncelAbort"
};
IF DoIt[@p]#0 THEN ERROR InvalidProcess[p];
};
Cancels abort request for process.
AbortPending:
PUBLIC
PROC []
RETURNS [abortPending:
BOOLEAN] ~
TRUSTED {
DoIt:
PROC []
RETURNS [
BOOLEAN] ~
TRUSTED
MACHINE
CODE {
"XRortPending"
};
RETURN [DoIt[]];
};
CheckForAbort:
PUBLIC PROC ~ {
AbortPending:
PROC
RETURNS [
BOOL] ~
TRUSTED
MACHINE
CODE {
"XRortPending"
};
CancelAbort:
PROC [
POINTER
TO
PROCESS]
RETURNS [
INT] ~
TRUSTED
MACHINE
CODE {
"XRncelAbort"
};
IF AbortPending[]
THEN {
[] ¬ CancelAbort[NIL];
ERROR ABORTED;
}
};
DisableAborts:
PUBLIC PROC [pCondition: ConditionPointer]
= {
DoIt:
PROC [pCondition: ConditionPointer] ~
TRUSTED
MACHINE
CODE {
"XR𡤍isableAborts"
};
DoIt[pCondition];
};
EnableAborts:
PUBLIC PROC [pCondition: ConditionPointer] = {
DoIt:
PROC [pCondition: ConditionPointer] ~
TRUSTED
MACHINE
CODE {
"XR𡤎nableAborts"
};
DoIt[pCondition];
};
Control of Scheduling
Pause:
PUBLIC
PROC [ticks: Ticks] ~
TRUSTED {
DoIt:
PROC [
CARD]
RETURNS [
INT] ~
TRUSTED
MACHINE
CODE {
"XR←PauseAbortable"
};
IF DoIt[ticks] # 0 THEN ERROR ABORTED;
};
PauseMsec:
PUBLIC
PROC [ms: Milliseconds] ~ {
ticks: Ticks ¬ MsecToTicks[ms];
Pause[ticks]
};
Yield:
PUBLIC
PROC ~ {
DoIt:
PROC ~
TRUSTED
MACHINE
CODE {
"XR←Yield"
};
DoIt[];
};
Process validation
ValidateProcess:
PUBLIC
PROC [p:
PROCESS] ~
TRUSTED {
DoIt:
PROC [
POINTER TO PROCESS]
RETURNS [
INT] ~
TRUSTED
MACHINE
CODE {
"XR←ValidateCT"
};
IF DoIt[@p]#0 THEN ERROR InvalidProcess[p];
};
InvalidProcess: PUBLIC ERROR [process: PROCESS] ¬ RuntimeError.InvalidProcess;
Process support (formerly in ProcessSupport.c)
ExternalNames:
PROC [] =
TRUSTED
MACHINE
CODE {
"^ExternalNames\n";
"XRWait XR←Wait\n";
"XRJoin XR←Join\n"
};
Should WaitCV and JoinCT come from a PCROps.mesa interface or some such?
XRWaitCV: PROC [cond: POINTER, lock: POINTER] RETURNS [i: INT] ~ TRUSTED MACHINE CODE {"XR←WaitCV"};
XRWait:
PROC [lock:
POINTER, cond:
POINTER] = {
IF XRWaitCV[cond, lock] # 0 THEN ERROR RuntimeError.Aborted
};
abortableJoin: BOOL ¬ TRUE;
badRES: INT ¬ 0; -- for debug
XRJoin:
PROC [process:
PROCESS]
RETURNS [
POINTER] =
TRUSTED {
NegErrno: TYPE ~ INT;
EABORTED: NegErrno ~ -1024; -- cf UnixErrno.mesa
XRTryJoinCT: PROC [pp: POINTER TO PROCESS, abortable: BOOL, resultp: POINTER TO POINTER] RETURNS [NegErrno] ~ TRUSTED MACHINE CODE {"XR←TryJoinCT"};
r: POINTER ¬ NIL;
res: NegErrno ~ XRTryJoinCT[pp: @process, abortable: abortableJoin, resultp: @r];
SELECT res
FROM
0 => RETURN [r];
EABORTED => ERROR ABORTED;
ENDCASE => { badRES ¬ res; ERROR RuntimeError.InvalidProcess[process] };
};
XRJoin: PROC [process: PROCESS] RETURNS [POINTER] = TRUSTED {
XRJoinCT: PROC [pp: POINTER TO PROCESS] RETURNS [POINTER] ~ TRUSTED MACHINE CODE {"XR←JoinCT"};
r: POINTER ¬ XRJoinCT[@process];
IF LOOPHOLE[r, INT] = -1 THEN ERROR RuntimeError.InvalidProcess[process];
RETURN[r]};
ExternalNames[];
END.
CHauser, February 16, 1989: Fixed bug in CheckForAbort. Didn't clear the abort request.
CHauser, February 21, 1989: Added CancelAbort.
JKF, May 31, 1991 11:16:43 am PDT: Folded in ProcessSupport.c.
MFP, March 4, 1992 11:41:12 pm PST: provided for abortable JOIN