-- ProcessOperations.mesa (last edited by Knutsen on December 9, 1980  10:18 PM)

DIRECTORY
  PrincOps USING [PSBreg, PTCreg, WDCreg],
  Mopcodes USING [
    zBCAST, zDWDC, zME, zMRE, zMXD, zMXW, zNOTIFY, zREQUEUE, zRR, zWR],
  PSB USING [ProcessStateBlock, PsbHandle, PsbIndex, Queue, QueueHandle, Ticks];

ProcessOperations: DEFINITIONS =

  BEGIN OPEN PSB;

  QueueHandle: TYPE = PSB.QueueHandle;

  Enter: PROCEDURE [POINTER TO MONITORLOCK] RETURNS [success: BOOLEAN] = MACHINE
    CODE BEGIN Mopcodes.zME END;

  LongEnter: PROCEDURE [LONG POINTER TO MONITORLOCK] RETURNS [success: BOOLEAN] =
    MACHINE CODE BEGIN Mopcodes.zME END;

  Exit: PROCEDURE [POINTER TO MONITORLOCK] = MACHINE CODE BEGIN Mopcodes.zMXD END;

  LongExit: PROCEDURE [LONG POINTER TO MONITORLOCK] = MACHINE CODE
    BEGIN Mopcodes.zMXD END;

  Wait: PROCEDURE [
    POINTER TO MONITORLOCK, POINTER TO CONDITION, --timeout:--CARDINAL] = MACHINE
    CODE BEGIN Mopcodes.zMXW END;

  LongWait: PROCEDURE [
    LONG POINTER TO MONITORLOCK, LONG POINTER TO CONDITION,
    --timeout:--CARDINAL] = MACHINE CODE BEGIN Mopcodes.zMXW END;

  ReEnter: PROCEDURE [POINTER TO MONITORLOCK, POINTER TO CONDITION]
    RETURNS [success: BOOLEAN] = MACHINE CODE BEGIN Mopcodes.zMRE END;

  LongReEnter: PROCEDURE [LONG POINTER TO MONITORLOCK, LONG POINTER TO CONDITION]
    RETURNS [success: BOOLEAN] = MACHINE CODE BEGIN Mopcodes.zMRE END;

  Notify: PROCEDURE [POINTER TO CONDITION] = MACHINE CODE
    BEGIN Mopcodes.zNOTIFY END;

  LongNotify: PROCEDURE [LONG POINTER TO CONDITION] = MACHINE CODE
    BEGIN Mopcodes.zNOTIFY END;

  Broadcast: PROCEDURE [POINTER TO CONDITION] = MACHINE CODE
    BEGIN Mopcodes.zBCAST END;

  LongBroadcast: PROCEDURE [LONG POINTER TO CONDITION] = MACHINE CODE
    BEGIN Mopcodes.zBCAST END;

  Requeue: PROCEDURE [
    from: LONG POINTER TO Queue, to: LONG POINTER TO Queue, p: PsbHandle] =
    MACHINE CODE BEGIN Mopcodes.zREQUEUE END;

  EnableAndRequeue: PROCEDURE [
    from: LONG POINTER TO Queue, to: LONG POINTER TO Queue, p: PsbHandle] =
    -- Note: this depends on having one instruction after enabling.
    MACHINE CODE BEGIN Mopcodes.zDWDC; Mopcodes.zREQUEUE END;

  ReadPSB: PROCEDURE RETURNS [currentProcess: PsbHandle] = MACHINE CODE
    BEGIN Mopcodes.zRR, PrincOps.PSBreg END;

  WritePSB: PROCEDURE [currentProcess: PsbHandle] = MACHINE CODE
    BEGIN Mopcodes.zWR, PrincOps.PSBreg END;

  HandleToIndex: PROCEDURE [handle: PsbHandle] RETURNS [PsbIndex] = INLINE {
    RETURN[LOOPHOLE[handle, CARDINAL]/SIZE[ProcessStateBlock]]};

  IndexToHandle: PROCEDURE [index: PsbIndex] RETURNS [PsbHandle] = INLINE {
    RETURN[LOOPHOLE[index*SIZE[ProcessStateBlock]]]};

  ReadPTC: PROCEDURE RETURNS [time: Ticks] = MACHINE CODE
    BEGIN Mopcodes.zRR, PrincOps.PTCreg END;

  WritePTC: PROCEDURE [time: Ticks] = MACHINE CODE
    BEGIN Mopcodes.zWR, PrincOps.PTCreg END;

  ReadWDC: PROCEDURE RETURNS [countDisabled: CARDINAL] = MACHINE CODE
    BEGIN Mopcodes.zRR, PrincOps.WDCreg END;

  WriteWDC: PROCEDURE [countDisabled: CARDINAL] = MACHINE CODE
    BEGIN Mopcodes.zWR, PrincOps.WDCreg END;

  END.