Program TSTLOCK;

{ Version 
  File:[22,311]TSTLOCK.PAS
  Author: Phil Hannay.  17-Jan-86.
  Last Edit: 17-JAN-1987 23:52:49 
  History:


Testing P3UTIL module(s): LOCK,UNLOCK

}

{$nolist}
{[a+,b+,l-,k+,r+] Pasmat }
%INCLUDE 'EX:[22,320]GENERAL3.TYP';
%INCLUDE 'EX:[22,320]WAIT.EXT';
%INCLUDE 'EX:[22,320]LOCK.EXT';
%INCLUDE 'EX:[22,320]UNLOCK.EXT';

{$list}

Var
  filstat, i, count, timeout, iflag, delay, loops: integer;
  flag: event_flag;
  job: ch3;
  port: ch5;
  resource: text;

Begin
Writeln('Begin LOCK/UNLOCK testing');
Writeln;
write('Enter job id (3 char)> ');
readln(job);
write('Enter flag number to lock> ');
readln(iflag);
flag:=f0;
for i:=1 to iflag do flag:=succ(flag);
write('Enter timeout value> ');
readln(timeout);
write('Enter port (ttn:) to out put messages');
readln(port);
write('Enter extra time to keep lock on> ');
readln(delay);
write('Enter number of interations before exit> ');
readln(loops);
for count:= 1 to loops do
  begin
  if lock(flag,timeout) 
    then begin
      { successful lock}
      writeln(job,' locking flag ',iflag:1,' for ',delay:1,' secs');
      rewrite(resource,port,,filstat);
      if filstat = -1 then writeln(job,' rewrite failed');
      writeln(resource,job,'->',port);
      writeln(resource,job,'->',port);
      writeln(resource,job,'->',port);
      writeln(resource,job,'->',port);
      close(resource);
      wait(f1,delay,seconds);
      if unlock(flag)
        then begin
          { successful unlock }
          writeln(job,' unlocked flag ',iflag:1,' after ',delay:1,' secs');
          end
        else begin
          { unlock failed }
          writeln(job,' tried to unlock flag ',iflag:1,' after ',
                         delay:1,' secs but failed');
          end;
      end
    else begin
      { unsuccessful lock }
      writeln(job,' tried to lock flag ',iflag:1,' but failed after ',
                      delay:1, ' secs wait');
      end;
  end;
writeln;
writeln(job,' ending, lock/unlock testing complete');
writeln;
end.
