Process.mesa
last edited by: Levin on June 14, 1983 4:04 pm
DIRECTORY
PrincOps USING [
ConditionVariable, Monitor, NoTimeout, PDA, Priority, PsbHandle, PsbNull, Ticks, UnlockedEmpty],
PrincOpsUtils USING [
DisableInterrupts, EnableAndRequeue, PsbHandleToIndex, ReadPSB];
Process: DEFINITIONS IMPORTS PrincOpsUtils =
BEGIN
Ticks: TYPE = PrincOps.Ticks;
Milliseconds: TYPE = CARDINAL;
Seconds: TYPE = CARDINAL;
Initializing monitors and condition variables
InitializeMonitor: PROC [monitor: LONG POINTER TO MONITORLOCK] = INLINE {
LOOPHOLE[monitor^, PrincOps.Monitor] ← PrincOps.UnlockedEmpty};
InitializeCondition: PROC [condition: LONG POINTER TO CONDITION, ticks: Ticks] = INLINE {
LOOPHOLE[condition^, PrincOps.ConditionVariable] ← [
condition: [tail: PrincOps.PsbNull, abortable: FALSE, wakeup: FALSE],
timeout: IF ticks=PrincOps.NoTimeout THEN PrincOps.NoTimeout+1 ELSE ticks
]
};
MsecToTicks: SAFE PROC [Milliseconds] RETURNS [Ticks];
SecondsToTicks: SAFE PROC [Seconds] RETURNS [Ticks];
TicksToMsec: SAFE PROC [Ticks] RETURNS [Milliseconds];
Timeouts
SetTimeout: PROC [condition: LONG POINTER TO CONDITION, ticks: Ticks] = INLINE {
condition.timeout ← IF ticks = PrincOps.NoTimeout THEN PrincOps.NoTimeout+1 ELSE ticks};
DisableTimeout: PROC [condition: LONG POINTER TO CONDITION] = INLINE {
condition.timeout ← PrincOps.NoTimeout};
Detaching processes
Detach: PROC [PROCESS];
Identity of the currently executing process
GetCurrent: SAFE PROC RETURNS [PROCESS] = TRUSTED INLINE {
RETURN[LOOPHOLE[PrincOpsUtils.PsbHandleToIndex[PrincOpsUtils.ReadPSB[]]]]};
Priorities of processes
Priority: TYPE = PrincOps.Priority;
The reserved priority levels (0, 5, 7) should not be used except by wizards.
priorityIdleProcess: Priority = 0;
priorityBackground, priorityClient0: Priority = 1;
priorityNormal, priorityClient1: Priority = 2;
priorityForeground, priorityClient2: Priority = 3;
priorityClient3: Priority = 4;
priorityFaultHandlers: Priority = 5;
priorityRealTime: Priority = 6;
prioritySwatWatcher: Priority = 7;
SetPriority: SAFE PROC [p: Priority] = TRUSTED INLINE {
h: PrincOps.PsbHandle;
h ← PrincOpsUtils.ReadPSB[];
PrincOps.PDA[h].link.priority ← p;
PrincOpsUtils.DisableInterrupts[]; -- (to cancel subsequent enable)
move to appropriate spot in ready queue:
PrincOpsUtils.EnableAndRequeue[@PrincOps.PDA.ready, @PrincOps.PDA.ready, h];
};
GetPriority: SAFE PROC RETURNS [Priority] = TRUSTED INLINE {
RETURN[PrincOps.PDA[PrincOpsUtils.ReadPSB[]].link.priority]};
Aborting a process
Abort: PROC [UNSPECIFIED]; --parameter should be any process
DisableAborts: PROC [pCondition: LONG POINTER TO CONDITION] = INLINE {
LOOPHOLE[pCondition^, PrincOps.ConditionVariable].condition.abortable ← FALSE};
EnableAborts: PROC [pCondition: LONG POINTER TO CONDITION] = INLINE {
LOOPHOLE[pCondition^, PrincOps.ConditionVariable].condition.abortable ← TRUE};
Control of Scheduling
Pause: SAFE PROC [ticks: Ticks];
Yield: SAFE PROC = TRUSTED INLINE {
PrincOpsUtils.DisableInterrupts[]; -- (to cancel subsequent enable)
PrincOpsUtils.EnableAndRequeue[
@PrincOps.PDA.ready, @PrincOps.PDA.ready, PrincOpsUtils.ReadPSB[]];
};
SetTimeSlice: SAFE PROC [ticks: Ticks];
Process validation
ValidateProcess: PROC [UNSPECIFIED];
InvalidProcess: ERROR [process: UNSPECIFIED];
END.