Action
Function
Header
Header Header
Contains
Contains Contains
Zero
Positive Negative
Value Value LIFO LOCK (The incoming element is at location AI SRR is free. SRR is in use. Store the contents Set the header to of the header into location A +4.
a negative value. Store the address A into the header.
Use the SRR. WAIT; the ECB is at location A.
LI FO UNLOCK Error Someone is The list is empty.
waiting for the Store zeros into SRR. Move the the header. The
pointer from the SRR is free. "last in" element into the header. POST; the ECB
is in the "Iast in" element. The following routines allow enabled code to perform the
actions described in the previous chart.
LIFO LOCK Routine:
Initial conditions:
GRI contains the address of the incoming element.
GR2 contains the address of the header. LLOCK SR 3,3 GR3 ::;: 0 ST 3,0(1) INITIALIZE THE ECB
LNR 0,1 GRO = A NEGATIVE VALUE TRYAGN CS 3,0,0(2) SET tHE HEADER TO A NEGATIVE V ALUE IF THE HEADER CONĀ­ TAINS ZEROS BE USE DID THE HEADER CONTAIN ZEROS? ST 3,4(1) NO, STORE THE VALUE OF THE
HEADER INTO THE POINTER IN
THE INCOMING ELEMENT CS 3,1,0(2) STORE THE ADDRESS OF THE
INCOMING ELEMENT INTO THE
HEADER
LA 3,0(0) GR3 = 0 BNE TRYAGNDID THE HEADER GET UPDATED?
WAIT (1) YES, WAIT FOR THE RESOURCE; THE ECB IS IN THE INCOMING
ELEMENT USE [ANY INSTRUCTION] LIFO UNLOCK Routine:
Initial conditions:
GR2 contains the address of the header. LUNLK L 1,0(2) GRI ::;: THE CONTENTS OF THE
A
B
EXIT
LTR 1,1
BM B
L 0,4(1) CS 1,0,0(2) HEADER DOES THE HEADER CONTAIN A
NEGATIVE VALUE? NO, LOAD THE POINTER FROM THE "LAST IN" ELEMENT AND STORE IT
IN THE HEADER
BNE A DID THE HEADER GET UPDATED? POST (1) YES, POST THE "LAST IN" ELEMENT
B EXIT CONTINUE SR 0,0 THE HEADER CONTAINS A NEGATIVE CS 1,0,0(2) VALUE; FREE THE HEADER AND
BNE A CONTINUE [ANY INSTRUCTION] Page of GA22-7000-4 Revised September 1, 1975
By TNL: GN22-0498
Note that the L 1,0(2) instruction at location LUNLK
would have to be CS 1,1,0(2) if it were not for the rule
that a full word fetch starting on a word boundary must
fetch the word such that if another CPU changes the word
being fetched, either the entire new or the entire old value
of the word, and not a combination of the two, is obtained.
LOCK/UNLOCK with FIFO Queuing for Contentions
Both a header and a free element are associated with the SRR. Each program using the SRR must provide an element
regardless of whether contention occurs. The element proĀ­
vided by the program becomes the new free element, and
the old free element becomes the program's new current
element. The free element is initialized to contain a posted
ECB. In the example, the element need be only a single
word. In some cases, the element could be made larger to
include a reverse pointer to the previous element.
The following chart describes the action taken for FIFO LOCK and FIFO UNLOCK routines.
Function FIFO LOCK (The incoming element is at location A) FIFO UNLOCK Action
Store the address A into the header. WAIT; the ECB is at the location addressed by the old contents of the
header. POST; the ECB is at the location that
you specified as an element when you locked. The following routines allow enabled code to perform the
actions described in the previous chart.
FIFO LOCK Routine:
Initial conditions: PNTRS is a doubleword containing two pointers. The first
word is a pointer to the current element owned by this
program. The second word is a pointer to the previous
element owned by this program.
GR3 contains the address of the header. FLOCK L 2,PNTRS GR2 = ADDRESS OF THE SR ST L
1,1 1,0(2) 1,0(3) CURRENT ELEMENT
GRI = ZERO INITIALIZE THE ECB
GRI = CONTENTS OF THE OLD ELEMENT TRY AGN CS 1,2,0(3) STORE THE ADDRESS OF THE USE BNE TRY AGN CURRENT ELEMENT INTO THE
HEADER, CURRENT ELEMENT BECOMES NEW FREE ELEMENT
STM 1,2PNTRS SAVE THE ADDRESSES IN GRI
WAIT (1) , AND GR2 FOR FUTURE USE, CURRENT ELEMENT BECOMES PREVIOUS ELEMENT, OLD FREE ELEMENT BECOMES CURRENT ELEMENT
GRI CONTAINS THE ADDRESS OF THE ECB [ANY INSTRUCTION] I:(' < , k Appendix I. Number Representation and Instruction-Use Examples 313
Page of GA22-7000-4 Revised September 1, 1975
By TNL: GN22-0498 J?IFO UNLOCK Routine:
Initial conditions: PNTRS is the same location used in the FIFO LOCK routine. FUNLK L 1,PNTRS+4 GRI CONTAINS THE ADDRESS POST (1) OF THE PREVIOUS ELEMENT,
THAT IS, THE ELEMENT THAT WAS ADDED IN THE FLOCK ROUTINE. CONTINUE [ANY INSTRUCTION] Free-Pool-List Manipulation It is anticipated that a program will need to add and delete
items from a free list without using the lock/unlock routines.
This is especially likely since the lock/unlock routines reĀ­ quire s.torage elements for queuing and may require working
storage. The lock/unlock routines discussed previously allow
simultaneous "lockers" but permit only one "'unlocker" at
a time. In such a situation, multiple additions and a single
deletion to the list may all occur simultaneously, but multiĀ­ ple deletions cannot occur at the same time. In the case of
a chain of pointers containing free storage buffers, multiple
deletions along with additions can occur simultaneously. In
this case, the removal cannot be done using the CS instrucĀ­ tion without a certain degree of exposure. Consider a chained list of the type used in the LIFO lock/
unlock example. Assume that the first two elements are at
locations A and B, respectively. If one program attempted
to remove the first element and was interrupted between
the fourth and fifth instructions of the LUNLK routine,
the list could be changed so that elements A and C are the
first two elements when the interrupted program resumes
execution. The CS instruction would then succeed in storing
the value B into the header, thereby destroying the list.
The probability of the occurrence of such list destruction
can be reduced to near zero by appending to the header a
counter that indicates the number of times elements have
been added to the list. The use of a 32-bit counter guaranĀ­ tees that the list will not be destroyed unless the following
events occur, in this exact sequence:
1. An unlocker is interrupted between the fetch of the
pointer from the first element and the update of the
header.
2. The list is manipulated, including the deletion of the eleĀ­ ment referenced in step 1, and exactly 2
32
- 1 additions
to the list are performed. Note that this takes on the
order of days to perform in any practical situation.
3. The element referenced in step 1 is added to the list.
4. The unlocker interrupted in step 1 resumes execution.
The routines ADD TO FREE LIST and DELETE FROM FREE LIST use such a counter in order to allow multiple,
simultaneous additions and removals at the head of a chain
of pointers.
The list consists of a doubleword header and a chain of
elements. The first word of the header contains a pointer
314 System/370 Principles of Operation
to the first element in the list. The second word of the
header contains a 32-bit counter indicating the number of
additions that have been made to the list. Each elemen t
contains a pointer to the next element in the list. A zero
value indicates the end of the list.
The following chart describes the free-pool-list manipuĀ­ lation.
Function
ADD TO LIST (The incoming
element is at
location AI DELETE FROM LIST Action Hellder=O, Count Header=A, Count, Store the first word of the header into location A. Store the address A into the first word of the header.
Decrement the second word of the header by one.
The list is empty. Set the first word of the
header to the value of the
contents of location A.
Use element A.
The following routines allow enabled code to perform the
free-pool-list manipulation described in the chart.
ADD TO FREE LIST Routine:
Initial conditions:
GR2 contains the address of the element to be added.
GR4 contains the address of the header.
ADDQ LM 0,1,0(4) GRO,GRI = CONTENTS OF THE
TRYAGN ST LR
BCTR CDS BNE 0,0(2) 3,1 3,0 0,2,0(4 )
TRYAGN
HEADER POINT THE NEW ELEMENT TO THE TOP OF THE LIST MOVE THE COUNT TO GR3
DECREMENT THE COUNT UPDA TE THE HEADER
DELETE FROM FREE LIST Routine:
Initial conditions:
GR4 contains the address of the header.
DELETQ LM 2,3,0(4) GR2,GR3 = CONTENTS OF THE
HEADER
TR Y AGN L TR 2,2 IS THE LIST EMPTY? BZ EMPTY YES, GET HELP L 0,0(2) NO, GRO= THE POINTER FROM THE FIRST ELEMENT
LR 1,3 MOVE THE COUNT TO GRI CDS 2,0,0(4) UPDATE THE HEADER
BNE TRYAGN USE [ANY INSTRUCTION] THE ADDRESS OF THE REMOVED ELEMENT IS IN GR2
Note that the LM instructions at locations ADDQ and
DELETQ would have to be CDS instructions if it were not
for the rule that a doubleword fetch starting on a doubleĀ­ word boundary must fetch the doubleword such that if
another CPU changes the doubleword being fetched, either I the entire new or the entire old value of the doubleword,
and not a combination of the two, is obtained.
Previous Page Next Page