         << LINES .001/.009 ARE RESERVED FOR SYSTEMS INTEGRATION >>     00000001
<<----------------------------------------------------------------------00080000
*                                                                      *00081000
*                     HP3000  LOGGING PROCESS                          *00082000
*                                                                      *00083000
---------------------------------------------------------------------->>00084000
COMMENT                                                                 00085000
The logging buffer scheme is modified in April 86.  Prior to            00086000
this, the two DSTs %37 & %40 have the same size as the record           00087000
size of the logging files. When one of them is full, LOG is             00088000
awaken to write it out.                                                 00089000
The problem with it is, if some process is holding the FMAVT            00090000
SIR and the LOG BUF SIR, and waits for the LOG process to post          00091000
the buffers out.  In the meantime LOG needs to open a new log           00092000
file, and tries to get the FMAVT SIR: Deadlock.                         00093000
To minimize - but not entirely eliminate this problem - we              00094000
increased the number of buffers within each DST. Each will now          00095000
has 8 buffers instead of one (a buffer is one phyiscal log              00096000
record). Hopefully with this many buffers, we have virtually            00097000
wipe out the case where a process has to wait for a buffer,             00098000
which will prevent the deadlock from happening.                         00099000
;                                                                       00100000
DEFINE POST'BUF =                                              << 2129>>00176000
  BEGIN                                                        << 2129>>00176100
  ENABLE;                                                      << 2129>>00176200
  IF LOGOUTPUT THEN GO TO LP2;                                 << 2129>>00176300
  DISABLE;                                                     << 2129>>00176400
  END#;                                                        << 2129>>00176500
FREEX       = SYSDB+%175,  <<FREE POINTER IN CUR. DST >>       << 2129>>00260000
INTEGER BSIZE,    << BUFSIZE IN WORD >>                        << 2129>>00466000
        CURRENT'BUF, << BUFF# IN CURR. DST  >>                 << 2129>>00467000
        BUFNUM; << BUF # TO WORK ON >>                         << 2129>>00468000
INTEGER SAVE'FLAG;                                             << 2285>>00468100
$EDIT VOID=1380000                                             << 2129>>01355000
$EDIT VOID=1475000                                             << 2129>>01440000
     TOS := @LBUF((BUFNUM-1)*BSIZE); << @start of cur. buf >>  << 2129>>01500000
   SAVE'FLAG := ABSOLUTE (FLAGX);                              << 2285>>01600050
   IF SAVE'FLAG.(14:1)  <> 0 THEN  << SWITCHLOG >>             << 2285>>01600060
      << if we are the right DST and buff num, then switch >>  << 2285>>01600070
      IF BX = SAVE'FLAG.(0:1) AND BUFNUM = SAVE'FLAG.(1:4)     << 2285>>01600080
         THEN LOGOUTPUT := TRUE; << new log file needed >>     << 2285>>01600090
   IF BUFNUM > 7 THEN                                          << 2129>>01601000
      BEGIN  << this is the last buf in this DST >>            << 2129>>01602000
      ABSOLUTE(BUF0X+BX).STATE := EMPTY;  <<MAKE IT EMPTY>>    << 2129>>01605000
      ABSOLUTE(LOGREC0X+BX) := 0;  << reset buffer rec cnt >>  << 2129>>01606000
      BUFNUM := 1;                                             << 2129>>01607000
      BX := (BX+1).(15:1); << switch to the other DST >>       << 2129>>01608000
      BUFDST := ABSOLUTE (BUF0X+BX) LAND %37777;               << 2129>>01608100
      END                                                      << 2129>>01609000
   ELSE  << still more buffs in this dst >>                    << 2129>>01610000
      BUFNUM := BUFNUM + 1; << increase to next buf >>         << 2129>>01611000
  << Set the log file's security to be accessed by the >>      <<S2145>>02115100
  << creator only                                      >>      <<S2145>>02115200
LP7: NEWSECMATRIX(0):=%040000;<< Give file 'CREATOR ONLY' >>   <<S2145>>02115300
     NEWSECMATRIX(1):=%000000;<< security                 >>   <<S2145>>02115400
     T:=1;  << NEWSECUREFLAG >>                                <<S2145>>02115500
     SAVEDB:=EXCHANGEDB(0); << Save prev DB if split-stack >>  <<S2145>>02115600
     FALTSEC(FILENUM,T,NEWSECMATRIX,,,ERRN);                   <<S2145>>02115700
     IF < THEN                                                 <<S2145>>02115800
          BEGIN                                                <<S2145>>02115900
          FCHECK(FILENUM,T);                                   <<S2145>>02116000
          GENMSG(1,450,%010000,T,-2); << Big FALTSEC err >>    <<S2145>>02116100
          END;                                                 <<S2145>>02116200
     EXCHANGEDB(SAVEDB);  << Restore DB >>                     <<S2145>>02116300
$EDIT VOID=2220000                                             << 2129>>02130000
            BSIZE := BUFSIZE &LSL(7);                          << 2129>>02291000
            BUFNUM := 1;                                       << 2129>>02292000
            BUFDST := ABSOLUTE (BUF0X+BX) LAND %37777;         << 2129>>02293000
            IF ABSOLUTE(FREEX) >= BSIZE AND << buf filled >>   << 2232>>02295000
      FLAGS := ABSOLUTE(FLAGX);                                << 2129>>02360000
$EDIT                                                          << 2129>>02365000
<<  >>                                                         << 2129>>02375000
      WHILE ABSOLUTE (BUF0X+BX).STATE = FULL DO                << 2129>>02380000
           POST'BUF;  << empty the full dst >>                 << 2129>>02381000
   IF ABSOLUTE (BUF0X+BX).STATE = CURRENT THEN                 << 2232>>02383000
      BEGIN                                                    << 2232>>02384000
      IF ABSOLUTE(FREEX) < BSIZE THEN                          << 2129>>02385000
         CURRENT'BUF := 1  << Freep is within the 1st buf >>   << 2129>>02386000
      ELSE                                                     << 2129>>02387000
         CURRENT'BUF := (ABSOLUTE(FREEX)/BSIZE) + 1;           << 2129>>02388000
      WHILE BUFNUM < CURRENT'BUF DO                            << 2129>>02390000
         POST'BUF;  << post the filled buffers >>              << 2129>>02391000
      END;                                                     << 2232>>02392000
$EDIT VOID = 2410000                                           << 2129>>02395000
      FLAGS.(15:1) := ABSOLUTE(STOPBITS).(1:1);<<SHUTDOWN>>    << 2129>>02415000
      IF FLAGS THEN GOTO LP6;                                  << 2285>>02420000
      SAVE'FLAG := ABSOLUTE (FLAGX);                           << 2285>>02420100
      IF SAVE'FLAG.(14:1)  <> 0 THEN  << SWITCHLOG >>          << 2285>>02420200
      << if awaken by SWITCHLOG, without any buf to post out>> << 2285>>02420300
      << then will go thru this code here to open new file >>  << 2285>>02420310
        IF BX = SAVE'FLAG.(0:1) AND BUFNUM-1 = SAVE'FLAG.(1:4) << 2285>>02420400
            THEN GOTO LP2;                                     << 2285>>02420500
      WAIT(%20,0);                                             << 2129>>02425000
                                                               << 2129>>02430000
      <<SLEEP UNTIL NEXT AWAKENING>>                           << 2129>>02435000
                                                               << 2129>>02440000
      GOTO LP1;                                                << 2129>>02445000
$EDIT                                                          << 2129>>02450000
                                                               << 2129>>02455000
LP6: IF FLAGS THEN << this is a shutdown, post last bufs >>    << 2129>>02456000
      BEGIN                                                    << 2129>>02457000
      WHILE ABSOLUTE (BUF0X+BX).STATE = FULL DO                << 2129>>02458000
           POST'BUF;  << empty the full dst >>                 << 2129>>02459000
      IF ABSOLUTE (BUF0X+BX).STATE = CURRENT THEN              << 2232>>02459800
      BEGIN                                                    << 2232>>02459900
      IF ABSOLUTE(FREEX) < BSIZE THEN                          << 2129>>02460000
         CURRENT'BUF := 1  << Freep is within the 1st buf >>   << 2129>>02461000
      ELSE                                                     << 2129>>02462000
         CURRENT'BUF := (ABSOLUTE(FREEX)/BSIZE) + 1;           << 2129>>02463000
      << note: in SHUTDOWN, if    the log file is full, we >>  << 2232>>02463100
      << don't open new one.  Just forget the rest, if any >>  << 2232>>02463200
      WHILE BUFNUM < CURRENT'BUF DO                            << 2129>>02464000
         POST'BUF;  << post the filled buffers >>              << 2129>>02465000
      IF ABSOLUTE(FREEX) MOD BSIZE <> 0 << part filled buf >> <<< 2232>>02465500
         THEN POST'BUF; << post this final one >>              << 2232>>02465600
      END; << if this is the CURRENT DST >>                    << 2232>>02465700
      END;                                                     << 2129>>02466000
    ENABLE;                                                    << 2129>>02467000
$EDIT VOID=2530000                                             << 2129>>02470000
$EDIT VOID=02600000                                            <<S2145>>02540000
         GO LP2                                                <<S2145>>02630000
      ABSOLUTE (FLAGX).(0:5) := 0; << ZERO OUT SAVED POINTERS ><< 2285>>02661000
      GOTO LP1;                                                << 2129>>02680000
