-- File: StatsHot.mesa,  Last Edit: HGM  January 7, 1981  12:35 PM

DIRECTORY
  StatsDefs USING [StatCounterIndex],
  StatsOps USING [];

StatsHot: PROGRAM EXPORTS StatsDefs, StatsOps =
  BEGIN OPEN StatsDefs;

  -- It would be nice if this were a MONITOR (locking StatsOps.statLock), but that slows things down a lot and complicates binding in the Pilot world.

  -- These are the master counters.  They are the only ones that get bumped by StatIncr and StatBump.  The numbers that StatSince prints out are obtained by subtracting two copies of statGrand.

  statGrand: PUBLIC POINTER TO ARRAY StatCounterIndex OF LONG CARDINAL ← NIL;

  StatIncr: PUBLIC PROCEDURE [which: StatCounterIndex] =
    BEGIN IF statGrand # NIL THEN statGrand[which] ← statGrand[which] + 1; END;

  StatBump: PUBLIC PROCEDURE [which: StatCounterIndex, howmuch: CARDINAL] =
    BEGIN
    IF statGrand # NIL THEN statGrand[which] ← statGrand[which] + howmuch;
    END;

  StatGetCounter: PUBLIC PROCEDURE [which: StatCounterIndex]
    RETURNS [LONG CARDINAL] =
    BEGIN RETURN[IF statGrand # NIL THEN statGrand[which] ELSE 0]; END;

  END.