-- CoordinatorInternal.mesa
-- Procedures internal to coordinator implementation.
-- Last edited by
--   MBrown on November 4, 1982 11:50 am

  DIRECTORY
    AlpineEnvironment,
    Coordinator,
    Process USING [Seconds];

CoordinatorInternal: DEFINITIONS LOCKS c USING c: Handle =
  BEGIN
  VolumeID: TYPE = AlpineEnvironment.VolumeID;
  Handle: TYPE = Coordinator.Handle;
  WorkerHandle: TYPE = Coordinator.WorkerHandle;
  Call: TYPE = Coordinator.Call;
  Results: TYPE = Coordinator.Results;

  SecondsTimeoutForResultsReturned: Process.Seconds = 5;
  SecondsWaitAfterCommFailure: INT = 15;
  MaxCoordinators: INT = 30;

  PassParms: PROC [p: Parms];
    -- Caller holds coordinator monitor for p.c.

  Parms: TYPE = RECORD [
    proc: Call, -- the proc to call
    c: Handle, -- to pass transID and to monitor return of results
    w: WorkerHandle, -- the worker to call
    newTrans: AlpineEnvironment.TransID, -- used by proc = prepare only
    requiredOutcome: AlpineEnvironment.CommitOrAbort -- used by proc = finish only
    ];

  ReturnResults: ENTRY PROC [c: Handle, w: WorkerHandle, r: Results] = INLINE {
    -- Caller holds no monitor.
    w.first.resultsOfMostRecentCall ← r;
    w.first.callInProgress ← none;
    NOTIFY c.resultsReturned;
    };

  NoticeCoordinatorBegin: PROC [trans: AlpineEnvironment.TransID];
    -- Called during analysis pass of recovery for each CoordinatorBegin record seen.
    --Supplies implicit parameters to InitTransIDGenerator below.

  InitTransIDGenerator: PROC [fileStore: VolumeID];
    -- Must be called before calling NextTransID.

  NextTransID: PROC [c: Handle];
    -- Atomically generates the next trans ID and writes a coordinatorBegin log
    --record containing it.  As a side-effect, fills in the transID and forceRecord
    --fields of c.

  END.