         PCC      0                                                             
         SYSTEM   SIG9P                                                         
         SYSTEM   OPTIONS                                                       
*                                                                               
*        OVERLAY CONTAINS JOB TERMINATION SUBROUTINES                           
*                                                                               
         DEF      TTJOB,TTJOBX                                                  
         DEF      TTJX                                                          
         DEF      JMTERM,JMTRMX                                                 
         DEF      FMJCL,FMJCEXIT                                                
         DO1      #ECB                                                          
         DEF      JMTENQ,JMTENQZ                                                
OLAYFLAG EQU      'TTJO'                                                        
         SYSTEM   CPRMON                                                        
         SPACE    2                                                             
TTJX     B        *R8                                                           
         TITLE    '** TTJOB **'                                                 
         TITLE    '** TTJOB - JOB CONTROLS SUBROUTINE **'                       
*                                                                               
*                 **********  CLEAN UP JOB CONTROLS ***********                 
*                                                                               
TTJOB    PUSH     5,R4              SAVE EXIT                                   
A:TTJOB  EQU      TTJOB                                                         
*                                   R6=JOB ID                                   
         CI,R6    BKGJID                                                        
         BE       TTJ3              EXIT IF BACKGROUND                          
         DO       #TJE                                                          
         BAL,R8   TTLN                                                          
         B        TTJ1              B IF NON-TJE TERMINAL                       
         DISABLE                                                                
         LB,R0    DCTTJE,R2                                                     
         CI,R0    TJEACT                                                        
         BANZ     TTJ3              B, TEX NOT READY FOR KJOB                   
         FIN      #TJE                                                          
*                                                                               
TTJ1     RES      0                                                             
         ENABLE                                                                 
         LI,R0    0                                                             
         STW,R0   LMIJID,R5         CLEAR JID TO DELETE TASK                    
         LB,R4    LMI#              NR OF LMI ENTRIES                           
         LW,R8    RUN99             LMI REENTRANCE VALUE                        
TTJ1A    RES      0                                                             
         LW,R0    LMIJID,R4                                                     
         CB,R6    R0                                                            
         BE       TTJ3              B IF ANOTHER TASK IN JOB                    
         BDR,R4   TTJ1A                                                         
         DISABLE                                                                
         CW,R8    RUN99                                                         
         BNE      TTJ1              B IF REENTERED                              
*                                                                               
*        NO OTHER TASKS IN JOB.  KILL IT                                        
*                                                                               
         LW,R4    SJI1,R6           SET THE 'T' BIT IN JCB                      
         LW,R0    0,R4                  PREVENTS NEW TASKS                      
         OR,R0    XJCBJTM               FROM BEING INITIATED                    
         STW,R0   0,R4                  IN JOB                                  
         MTW,1    JOB99                 INCR JOB RE-ENT COUNT                   
         ENABLE                     CLEANUP ALL JOB CONTROLS,                   
         BAL,R8   JMTERM                AND RELEASE SPACE NOW                   
TTJ3     ENABLE                                                                 
         PULL     5,R4              RESTORE REGS AND EXIT                       
TTJOBX   B        *R8                                                           
         TITLE    'JM SUBROUTINE, CLEAN UP JOB CONTROLS'                        
************************************************************                    
*                                                          *                    
*    JMTERM- CALLED BY TASK TERMINATION WHEN LAST TASK IN  *                    
*            THE JOB HAS BEEN TERMINATED. JMTERM DEQUEUES  *                    
*            JOB LEVEL ITEMS, RUNS DOWN IO,    FREES JOB   *                    
*            BLOCKING BUFFERS, FREES JCB SPACE AND CLEARS  *                    
*            THE SJI ENTRIES.  IS IN AN OVERLAY.           *                    
*        SUBROUTINES USED:                                 *                    
*            JMTENQ                                        *                    
*            FMJCL                                         *                    
*            RELTEMP                                       *                    
*        ENTERED WITH JOB ID IN R6 VIA BAL,R8              *                    
************************************************************                    
JMTERM   RES      0                                                             
         PUSH     R8                SAVE EXIT                                   
         CI,R6    BKGJID                                                        
         BE       JMTERM5           B IF BKG: PARTIAL CLEANUP                   
         LW,R1    SJI1,R6           JCB ADDRESS                                 
         LI,R7    0                                                             
         XW,R7    JCBNXLM,R1        GET POSSIBLE NEXT LM FILE ID                
         BEZ      %+2               B IF NOT THERE                              
         BAL,R8   RELTEMP           RELEASE NEXT LM FILE ID BLOCK               
         DO       #TJE                                                          
         BAL,R8   TTLN              IS IT A TERMINAL JOB                        
         B        JMTERM1A          NO                                          
         LB,R0    DCTTJE,R2         GET FLAGS                                   
         CI,R0    TJETEX+TJEACT     TIME TO KJOB                                
         BANZ     JMTERMX           NO                                          
*                                                                               
JMTERM1A EQU      %                                                             
         FIN      #TJE                                                          
         BAL,R8   FMJCL             CALL JOB CLOSE FILES                        
         LW,R1    SJI1,R6           SET R1=JCB ADDRESS                          
*                                   **** RELEASE JOB SEGMENTS****               
         BAL,R8   MMTJOB                SD CLEANUP, ALL OTHERS                  
*                                       DO CLEANUP                              
JMTERM1  RES      0                                                             
*                                                                               
         DO       #TJE                                                          
         LW,R1    SJI1,R6           REFETCH JCB ADDRESS                         
         LW,R7    JCBTABS,R1        GET TABS WORD                               
         BEZ      %+2                                                           
         BAL,R8   RELTEMP           RELEASE TAB SPACE                           
         FIN      #TJE                                                          
*                                                                               
         DO1      #ECB                                                          
         BAL,R8   JMTENQ            FREE JOB LEVEL ENQ'S                        
         LW,R7    JCBEDTH,R1            EDT CHAIN EMPTY?                        
         BNEZ     JMTERMCR          CRASH IF NONZERO                            
JMTERM2  RES      0                 FREE BLOCKING BUFFERS                       
         LW,R2   *R1                SEE IF ANY TABLES ARE LINKED FROM           
         AND,R2   Y2                    THE JCB.                                
         BEZ      JMTERM3             AET NOT LINKED                            
         LW,R7    JCBAET,R1           AET LINKED. RELEASE SPACE                 
         BAL,R8   RELTEMP                                                       
JMTERM3  LW,R2   *R1                                                            
         AND,R2   Y1                                                            
         BEZ      JMTERM4             JPT NOT LINKED                            
         LW,R7    JCBJPT,R1           JPT LINKED. RELEASE SPACE                 
         BAL,R8   RELTEMP                                                       
JMTERM4  LW,R7    R1                  RELEASE JCB SPACE                         
         BAL,R8   RELTEMP                                                       
         B        JMTERMB                                                       
*    BACKGROUND JOB RELEASE. DOES NOT RELEASE SPACE, BUT ZEROES AET AND         
*     JPT, AND RESTORES OPLB TABLES.                                            
JMTERM5  RES      0                                                             
         LH,R5    OPLBS1            NR OF OPLABELS                              
JMTERM51 RES      0                                                             
         CI,R5    C                                                             
         BE       %+3               B IF 'C' OPLB (SKIP IT)                     
         LB,R2    OPLBS2,R5                                                     
         STB,R2   OPLBS3,R5         RESET BKG OPLABEL TO SYSTEM VALUE           
         BDR,R5   JMTERM51                                                      
*                                                                               
         LD,R10   BKGNAME                                                       
         BAL,R8   TMFINDT           GET LM ID                                   
         B        %+2               B IF NOT FOUND                              
         BAL,R8   FMTCL             LMIRFT DRIVEN FILE CLOSING                  
         BAL,R8   FMJCL             RFT DRIVEN FILE CLOSING                     
         DO1      #ECB                                                          
         BAL,R8   JMTENQ            ENQ CLEANUP                                 
*                                                                               
         LW,R1    SJI1,R6           GET JCB ADDRESS                             
         LI,R5    0                                                             
         STW,R5   JCBTRPS,R1        ZERO SECONDARY TRAP CONTROLS                
         STW,R5   JCBTRPP,R1        ZERO PRIMARY   TRAP CONTROLS                
*  ZERO  JPT AND AET TSPACE IF LINKED                                           
JMTERM7  LW,R2   *R1                SEE IF AET LINKED                           
         AND,R2   Y2                                                            
         BEZ      JMTERM9           NOT LINKED                                  
         LW,R2    JCBAET,R1         LINKED                                      
         LB,R6    R2            AET TSPACE LENGTH                               
         BNEZ     JMTERM71                                                      
         LI,R6    256               ZERO MEANS 256 WORDS                        
JMTERM71  AND,R2  M24               MASK ADR                                    
         AI,R6   -1                 FOR BDR INDEX                               
JMTERM8  STW,R5  *R2,R6                                                         
         BDR,R6   JMTERM8                                                       
         STW,R5  *R2                                                            
JMTERM9  LW,R2   *R1                SEE IF JPT LINKED                           
         AND,R2   Y1                                                            
         BEZ      JMTERMX           B IF NOT LINKED                             
         LW,R2    JCBJPT,R1         LINKED                                      
         LB,R6    R2            JPT TSPACE LENGTH                               
         BNEZ     JMTERM91                                                      
         LI,R6    256               ZERO MEANS 256 WORDS                        
JMTERM91  AND,R2  M24                                                           
         AI,R6   -1                                                             
JMTERMA  STW,R5  *R2,R6                                                         
         BDR,R6   JMTERMA                                                       
         STW,R5  *R2                                                            
*                                FOR BKGD., LEAVE SJI ALONE                     
         B        JMTERMX                                                       
*                                                                               
*        END OF SPECIAL JMTERM FOR BKG                                          
*                                                                               
JMTERMB  LD,R10   ZEROS             CLEAR SJI ENTRIES                           
         DO       #TJE                                                          
         BAL,R8   TTLN              IS IT TERMINAL JOB                          
         B        JMTERMC           NO                                          
         DISABLE                                                                
         PUSH     R4                SAVE TASK ID                                
         LI,R4    TEXTID            GET TEX INDEX                               
         LW,R7    XSTISTRT          SET START BIT                               
         STS,R7   STIPRIO,R4                                                    
         BAL,R8   TMTRIG            TRIGGER                                     
         PULL     R4                RESORE TASK ID                              
         FIN      #TJE                                                          
JMTERMC  EQU      %                                                             
         STD,R10  SJI2,R6                                                       
         STW,R10  SJI1,R6                                                       
         STB,R10  SJI3,R6           DONE                                        
         ENABLE                                                                 
JMTERMX  PULL     R8                EXIT                                        
JMTRMX   B        *R8               EXIT OVERLAY                                
JMTERMCR CRASH    'JMTERM'                                                      
         BOUND    8                                                             
BKGNAME  TEXT     'BKG     '                                                    
         TITLE    '** TTJOB - FMJCL SUBROUTINE **'                              
****************                                                                
*   FMJCL      *                                                                
****************                                                                
*                                                                               
*    ROUTINE CLEANS UP ALL DCT AND RFT ENTRIES FOR THE                          
*    SPECIFIED JOB.                                                             
*                                                                               
*    AT ENTRY:    R6   ID FOR JOB TO CLEANUP                                    
*                 R8   LINK                                                     
*                                                                               
*    ROUTINE SAVES R6                                                           
*                                                                               
*    ROUTINE ALWAYS RETURNS +1                                                  
*                                                                               
FMJCL    RES      0                                                             
         PUSH     R8                SAVE LINK                                   
         LI,R7    8                                                             
         BAL,R8   GETTEMP           GET 8 WORDS OF TSPACE                       
         B        FMJCL3            CANT GET TSPACE                             
         ENABLE                                                                 
         LI,R1    7                                                             
         LW,R0    CLFPT-1,R1        MOVE FPT,DCB TO TSPACE                      
         STW,R0   *R7,R1                                                        
         BDR,R1   %-2                                                           
         LW,R2    R7                                                            
         AI,R2    3                 R2= DCB ADDRESS                             
         LW,R3    R7                                                            
         AI,R3    1                 R3= FPT ADDRESS                             
         AND,R2   M17                                                           
         AND,R3   M17                                                           
*  CLEANUP DCT ENTRIES                                                          
         LH,R1    DCT1              NO. OF DCT ENTRIES                          
FMJCL1   CB,R6    DCTJID,R1         IS IT IN SAME JOB                           
         BNE      FMJCL2            NO,BRANCH                                   
         LI,R0    1                                                             
         STB,R0   DCTDCB,R1         YES, FORCE DCB COUNT =0 IN CLOSE            
*   SET DCB FOR THE CLOSE                                                       
         LW,R15   CLDCB             DCB WORD 0                                  
         STW,R15  3,R7              STORE IN TSPACE                             
         LB,R15   DCT4,R1           DEVICE TYPE                                 
         SLS,R15  8                                                             
         AW,R15   R1                DEVICE INDEX                                
         AI,R15   X'8000'           SET DEVF BIT                                
         STW,R15  4,R7              STORE DCB WORD 1                            
         PUSH     7,R1                                                          
         BAL,R5   CLOSEDCB          CLOSE THE DCB                               
         NOP                        IGNORE ERRORS                               
         PULL     7,R1                                                          
FMJCL2   BDR,R1   FMJCL1                                                        
*  DELETE TSPACE                                                                
         BAL,R8   RELTEMP                                                       
*                                                                               
*  CLEANUP RFT ENTRIES                                                          
FMJCL3   RES      0                                                             
         ENABLE                                                                 
         LH,R7    RFT#              GET NUMBER OF RFT ENTRIES TO SCAN           
         LI,R1    -1                PHALSE FPT CODE FOR FINDDIR                 
FMJCL4   RES      0                                                             
         LD,R10   RFT1,R7                                                       
         BEZ      FMJCL5            B IF UNUSED ENTRY                           
         CB,R6    RFT9,R7                                                       
         BE       FMJCL45           YES, BRANCH                                 
         MTB,0    RFT9,R7           IS THE FILE SYSTEM SHARABLE                 
         BNEZ     FMJCL5            NO, CAN'T RELEASE THE BB                    
         MTW,0    RFT17,R7          IS THERE A BLOCKING BUFFER                  
         BEZ      FMJCL5            NO, NOTHING TO RELEASE                      
         CB,R6    RFT14,R7          DOES IT BELONG TO TERMING JOB               
         BNE      FMJCL5            NO, BRANCH                                  
         PUSH     7,R1              YES, RELEASE THE BLK BUFFER                 
         BAL,R4   WLBLOCK                                                       
         NOP                                                                    
         PULL     7,R1                                                          
         B        FMJCL5                                                        
FMJCL45  RES      0                                                             
         LD,R10   ZEROS                                                         
         CI,R6    BKGJID            IS BAKGROUND TERMINATING                    
         BNE      FMJCL4A           NO, BRANCH                                  
         LI,R2    C                 R2= C OPLB INDEX                            
         LI,R0    X'80'                                                         
         OR,R0    R7                R0= RFT INDEX IN OPLB TABLE FORMAT          
         CB,R0    OPLBS3,R2         IS THIS FILE THE C 'DEVICE'                 
         BE       FMJCL5            YES, CAN'T CLOSE C ASSIGNMENT               
         DO       #SYMB                                                         
         CW,R7    SM:C              IS THIS THE SYMBIONT INPUT FILE             
         BE       FMJCL5            YES, DON'T CLOSE IT                         
         FIN      #SYMB                                                         
         LW,R8    K:JCP1                                                        
         CI,R8    K4                IS TY KEYIN IN EFFECT                       
         BAZ      FMJCL4A           NO, BRANCH                                  
         CB,R0    K:JCP1,R2         YES, IS SAVED ASSIGNMENT THIS FILE          
         BE       FMJCL5            YES, CAN'T CLOSE THE FILE                   
FMJCL4A  RES      0                 NO, OK TO CLOSE THE FILE                    
         STB,R10  RFT13,R7          TOTAL USERS= 0                              
         STB,R10  RFT15,R7          BKGD USERS= 0                               
FMJCL4C  RES      0                                                             
         LW,R15   RENT:D            GET ACTIVITY COUNT                          
         PUSH     7,R1                                                          
         BAL,R5   CRFIL             CLOSE THE FILE                              
         B        FMJCL7            ERROR, R9=TYC                               
         PULL     7,R1                                                          
FMJCL5   BDR,R7   FMJCL4                                                        
         PULL     R8                RESTORE LINK                                
FMJCEXIT B        *R8               EXIT                                        
CLFPT    RES      0                 FPT FOR CLOSE                               
         GEN,8,24 X'15',CLDCB                                                   
         DATA     0                                                             
CLDCB    RES      0                 DCB FOR CLOSE                               
         DATA     X'05200003'                                                   
         DATA     0                                                             
         DATA     0                                                             
         DATA     0                                                             
         DATA     0                                                             
*                                                                               
*   ERROR PROCESSING FOR CRFIL SUBROUTINE CALL                                  
*                                                                               
FMJCL7   RES      0                                                             
         PULL     7,R1              CLEANUP STACK                               
         CI,R9    TYCREENT          TYC= REENTERED IN CLOSE                     
         BE       FMJCL4C           YES, TRY AGAIN                              
         B        FMJCL5            TRY NEXT FILE                               
         TITLE    '** TTJOB - JOB LEVEL ENQ CLEANUP **'                         
*******************                                                             
*    JMTENQ       *    SUBR TO CLEANUP JOB LEVEL ENQS                           
*******************                                                             
* ENTRY  R6       JOB ID                                                        
*        BAL,R8   JMTENQ                                                        
* EXIT   +1       NORMAL                                                        
* REGISTERS SAVED R6-R8                                                         
* STACK WORDS:    3                                                             
* SUBROUTINES:    TMDELAET                                                      
*                                                                               
         DO       #ECB                                                          
JMTENQ   PUSH     3,R6              SAVE R6, EXIT                               
         LW,R6    SJI1,R6           SET R6=JCB ADDRESS                          
         LW,R1    JCBAET,R6             R1=AET                                  
         BEZ      JMTENQX               NONE, EXIT                              
JMTENQ1  LW,R7    AETEDT,R1             R7=EDT                                  
         BEZ      JMTENQ2               NOT USED                                
         LW,R9    R7                SET FLAGS FOR JOB LEVEL DEQ                 
         BAL,R8   TMDELAET              FREE THE RESOURCE                       
JMTENQ2  AI,R1    AETSIZE           ADVANCE TO THE NEXT AET                     
         MTB,-2   R1                    DECR SIZE                               
         BNEZ     JMTENQ1               AND CONTINUE                            
*                                       JOB CLEANUP RELEASES                    
*                                       JOB LEVEL AET                           
JMTENQX  PULL     3,R6              RESTORE REGISTERS                           
         LW,R1    SJI1,R6                                                       
JMTENQZ  B        *R8                   EXIT                                    
         FIN      #ECB                                                          
*                                                                               
         OLAYEND                                                                
*                                                                               
         END                                                                    
