1 /****^  ***********************************************************
  2         *                                                         *
  3         * Copyright, (C) Honeywell Bull Inc., 1987                *
  4         *                                                         *
  5         * Copyright, (C) Honeywell Information Systems Inc., 1984 *
  6         *                                                         *
  7         * Copyright (c) 1972 by Massachusetts Institute of        *
  8         * Technology and Honeywell Information Systems, Inc.      *
  9         *                                                         *
 10         *********************************************************** */
 11 
 12 
 13 /* format: style4 */
 14 demand_deactivate: proc (a_segptr, a_code);
 15 
 16 /* Written March 30, 1976 by R. Bratt
 17 
 18    This module allows priveleged users to deactivate a segment if certain
 19    conditions obtain. These conditions are:
 20    *      the segment must be known in the calling process
 21    *      the segment must be active
 22    *      all users who have connected to the aste must have specified explicit_deact_ok,
 23    *         or this is force entry
 24    *      the aste must be deactivateable
 25 
 26    Modified for external static SST, 04/19/81, W. Olin Sibert
 27    Modified for $force entrypoint, 04/21/81, WOS
 28    Modified for $force_given_segno entrypoint, 02/28/82, J. Bongiovanni
 29    Modified to lock ast on search, 05/30/83, E. N. Kittlitz
 30    Modified to respect threaded-out-ness, 84-01-08 BIM.
 31 */
 32 
 33 dcl  a_segptr ptr parameter;
 34 dcl  a_seg_uid bit (36) aligned parameter;
 35 dcl  a_code fixed bin (35) parameter;
 36 
 37 dcl  segno fixed bin (17);
 38 dcl  code fixed bin (35);
 39 dcl  uid bit (36) aligned;
 40 dcl  force_sw bit (1) aligned;
 41 
 42 dcl  sst$demand_deact_attempts fixed bin (35) external static;
 43 dcl  sst$demand_deactivations fixed bin (35) external static;
 44 
 45 dcl  deactivate entry (ptr, fixed bin (35));
 46 dcl  get_kstep entry (fixed bin, pointer, fixed bin (35));
 47 dcl  lock$lock_ast entry ();
 48 dcl  lock$unlock_ast entry ();
 49 dcl  search_ast entry (bit (36) aligned) returns (pointer);
 50 
 51 dcl  error_table_$illegal_deactivation fixed bin(35) ext static;
 52 
 53 dcl  (baseno, binary, null) builtin;
 54 
 55 %page;
 56 
 57           force_sw = "0"b;                                  /* Don't, unless we're allowed to */
 58           goto FIND_UID;
 59 
 60 
 61 demand_deactivate$force_given_segno:
 62      entry (a_segptr, a_code);
 63 
 64           force_sw = "1"b;
 65 
 66 FIND_UID:
 67           segno = binary (baseno (a_segptr), 18);           /* Find the UID for the segment */
 68 
 69           call get_kstep (segno, kstep, code);
 70           if code ^= 0 then do;                             /* Bad segno, or something */
 71                a_code = code;
 72                return;
 73           end;
 74 
 75           uid = kste.uid;
 76           goto COMMON;
 77 
 78 
 79 demand_deactivate$force: entry (a_seg_uid, a_code);         /* Deactivate by UID, rather than segno, and force */
 80 
 81           uid = a_seg_uid;
 82           force_sw = "1"b;                                  /* Deactivate, if at all possible */
 83 
 84 
 85 COMMON:   code = 0;                                         /* Assume success */
 86           sst$demand_deact_attempts = sst$demand_deact_attempts + 1;
 87           call lock$lock_ast ();
 88 
 89 /* we don't go to the expense of deriving pvid, vtocx. If we have a double-uid,
 90    we'll either find the right segment active, or we'll harrass the other segment
 91    with the same uid.  In either case, the segment we want will end up inactive, if possible. */
 92 
 93           astep = search_ast (uid);
 94           if astep ^= null () then
 95                if force_sw | aste.explicit_deact_ok then do;/* We're allowed to try it */
 96                     if (astep -> aste.fp | astep -> aste.bp) = ""b
 97                     then do;
 98                          code = error_table_$illegal_deactivation;
 99                          go to RETURN;
100                     end;
101                     call deactivate (astep, code);          /* See what happens */
102 
103                     if code = 0 then sst$demand_deactivations = sst$demand_deactivations + 1;
104                end;                                         /* Record successes */
105 RETURN:
106           call lock$unlock_ast ();
107           a_code = code;
108           return;
109 
110 /*format: off */
111 %page; %include aste;
112 %page; %include kst;
113 
114      end demand_deactivate;