Each program then enters the address of
the element which it has provided into the header, while simultaneously it
removes the address previously contained
in the header. Thus, associated with any particular program attempting to use
the SRR are two elements, called the
"entered element" and the "removed
element." The "entered element" of one
program becomes the "removed element"
for the immediately following program.
Each program then waits on the removed element, uses the SRR, and then posts
the entered element.
When no contention occurs, that is, when
the second program does not attempt to
use the SRR until after the first
program is finished, then the POST of
the first program occurs before the WAIT
of the second program. In this case,
the bypass-post and bypass-wait routines
described in the preceding section are
applicable. For simplicity, these two
routines are shown only by name rather
than as individual instructions.
In the example, the element need be only
a single word, that is, an ECB. However, in actual practice, the element
could be made larger to include a point­
er to the previous element, along with a
program identification. Such informa­
tion would be useful in an error
situation to permit starting with the
header and chaining through the list of
elements to find the program currently
holding the SRR.
It should be noted that the element
provided by the program remains pointed
to by the header until the next program
attempts to lock. Thus, in general, the
entered element cannot be reused by the
program. However, the removed element is available, so each program gives up
one element and gains a new one. It is expected that the element removed by a
particular program during one use of the
SRR would then be used by that program
as the entry element for the next
request to the SRR.
It should be noted that, since the
elements are exchanged from one program
to the next, the elements cannot be
allocated from storage that would be
freed and reused when the program ends.
It is expected that a program would
obtain its first element and release its
last element by means of the routines
described in the section "Free-Pool
Manipulation" in this appendix.
The following chart describes the action
taken for FIFO LOCK and FIFO UNLOCK. Function Action FIFO LOCK Store address A
into the header.
(the incoming WAIT; the ECB is at
element is at the location addres-
location A) sed by the old con-
tents of the header. FIFO UNLOCK POST; the ECB is at
location A.
The following routines allow enabled
code to perform the actions described in
the previous chart. FIFO LOCK Routine:
Initial conditions:
GR3 contains the address of the header.
GR4 contains the address, A, of the
element currently owned by this
program. This element becomes the
entered element. FLOCK LR 2,4
SR
ST
L TRYAGN CS BC LR
1,1
1,0(2) 1,0(3) 1,2,0(3) 7,TRYAGN HSWAIT
GR2 now contains
address of ele­
ment to be
entered
GR1 = ° Initialize the ECB GR1 = contents of
the header
Enter address A into header
while remember­
ing old contents
of header into GR1; GR1 now
contains address
of removed
element
Removed element
becomes new cur­
rently owned
element
Perform bypass-
wa it rout i ne; if ECB already
posted, con-
t i nue; if not, wait; GR1 con­
tains the ad­
dress of the ECB USE [Any instruction] FIFO UNLOCK Routine:
Initial conditions:
GR2 contains the address of the removed
element, obtained during the FLOCK routine.
GR5 contains 40 00 00 00{16} Appendix A. Humber Representation and Instruction-Use Examples A-45
FUNLK LR 1,2 Place address of en-
tered element in
GR1; GR1 = address
of ECB to be posted SR 0,0 GRO = 0; GRO has a
post code of zero OR 0,5 Set bit 1 of GRO to
one HSPOST Perform bypass-post
routine; if ECB has
not been waited on,
then mark posted
and continue; if it
has been waited on,
then post CONTINUE [Any instruction] FREE-POOL 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 require
storage elements for queuing and may
require working storage. The
lock/unlock routines discussed previous­
ly allow simultaneous lock routines but
permit only one unlock routine at a
time. In such a situation, multiple
additions and a single deletion to the
list may all occur simultaneously, but
multiple 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 COMPARE AND SWAP instruction
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
A-46 System/370 Principles of Operation two elements when the interrupted
program resumes execution. The COMPARE AND SWAP 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 guar­
antees that the list will not be
destroyed unless the following events
occur, in the exact sequence:
1. An unlock routine 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 element refer­
enced in 1, and exactly 2
32
-1 addi­
tions 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 1 is
added to the list.
4. The unlock routine interrupted in 1
resumes execution.
The following routines use such a count­
er in order to allow multiple, simul­
taneous 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 to the
first element in the list. The second
word of the header contains a 32-bit
counter indicating the number of addi­
tions that have been made to the list.
Each element 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 manipulation.
Previous Page Next Page