perm filename IAUX2B.2[EAL,HE]1 blob sn#676514 filedate 1982-09-27 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00003 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	{$NOMAIN	Interpreter: Misc Level 2 routines }
C00004 00003	(* aux routines: cmonDisable, cmonCheck, cmonEnable *)
C00014 ENDMK
C⊗;
{$NOMAIN	Interpreter: Misc Level 2 routines }

%include ialhdr.pas;

{ Externally defined routines from elsewhere: }

	(* From ALLOC *)
procedure relNode(n: nodep);					external;

	(* From IAUX1A *)
procedure upTrans (var t: transp; tp: transp);			external;
procedure makeCmon(e: enventryp; vari: varidefp);		external;
procedure sendCmd;						external;

	(* From IAUX1B *)
procedure addPdb(var plist: pdbp; pn: pdbp);			external;
procedure deClkQueue(po: pdbp);					external;

(* aux routines: cmonDisable, cmonCheck, cmonEnable *)

procedure cmonDisable(c: cmoncbp); external;
procedure cmonDisable;
 var p,pp: pdbp; b: boolean; n,np: nodep;

 begin
 with c↑ do
  begin
  if enabled then		(* is it currently enabled? *)
    begin
    enabled := false;		(* disable it *)
    if cmon↑.oncond↑.ntype = forcenode then
      begin
      with msg↑ do
       begin
       cmd := forceoffcmd;
       bits := fbits;
       evt := c↑.evt;
       end;
      sendCmd;	(* tell force system to stop checking for this force condition *)
      end;
    if cmon↑.exprCm or (cmon↑.oncond↑.ntype = durnode) then deClkQueue(pdb)
     else
      begin				(* remove pdb from event queue *)
      p := evt↑.waitlist;
      pp := nil;
      while (p <> nil) and (p <> pdb) do begin pp := p; p := p↑.next end;
      if p <> nil then		(* found us, now splice us out of the list *)
	if pp = nil then evt↑.waitlist := p↑.next else pp↑.next := p↑.next;
      end;
    pdb↑.next := nil;
    end;
  end;
 end;

function cmonCheck: boolean; external;
function cmonCheck;
 var b: boolean; i: integer; env: environp; ev: enventryp;
 begin		(* make sure all cmon's in current environment have finished *)
 b := true;
 env := curInt↑.env↑.env[0];		(* point to first environment record *)
 i := 0;
 ev := env↑.vals[0];
 while (ev <> nil) and b do
  with ev↑ do
   begin				(* see if any cmons are running *)
   if etype = cmontype then
     begin				(* found a cmon *)
     if c↑.running then
       b := c↑.pdb↑.priority >= curInt↑.priority	(* is it running now? *)
      else cmonDisable(c);		(* if not disabled it *)
     end;
   i := i + 1;
   if i <= 9 then ev := env↑.vals[i]
    else
     begin
     i := 0;
     env := env↑.next;			(* use next env record *)
     if env <> nil then ev := env↑.vals[0] else ev := nil;
     end;
   end;
 cmonCheck := b;		(* true if no cmons are now running *)
 end;

procedure cmonEnable(e: enventryp); external;
procedure cmonEnable;
 var p: pdbp; b: boolean; pri: integer;
 begin
 with e↑.c↑ do
  if (enabled or running) and ((pdb↑.priority mod 10) < debugLevel) then
    makeCmon(e,cmon↑.cdef);   (* push old & make another for this debug level *)
 with e↑.c↑ do
  if running then enabled := true	(* if currently running, re-enable it *)
   else if not enabled then		(* is it currently enabled? *)
    begin
    enabled := true;			(* now it is *)
    pdb↑.status := runqueue;
    pdb↑.priority := (pdb↑.priority mod 10) + (10 * debuglevel);
    addPdb(activeInts,pdb);		(* add cmon to list of active processes *)
    if pdb↑.priority > curInt↑.priority then 
      resched := true;			(* need to swap us out *)
    end;
 end;