GDSX (Extended General Device Support) Manual

Service Routines
Extended General Device Support (GDSX) Manual529931-001
8-42
INIT^SEM
INIT^SEM
PSEM
VSEM
The checkpoint semaphore is defined by TSCODE and managed with the
GET^CPSEM and GIVE^CPSEM procedures.
A semaphore is first initialized with INIT^SEM. The semaphore can be defined in
global or extended memory; however, it is recommended that it is declared in global
memory, within a user private block, for example. If a backup GDSX process exists,
the semaphore must be initialized in both primary and backup GDSX processes. The
semaphore may then be acquired by calls to PSEM and released by calls to VSEM.
A task takes control of a semaphore when a call to PSEM inserts the address of the
task’s TCB (@TCB) into the first element of the semaphore structure (described in the
table below). If the semaphore is already owned, a task requesting ownership has its
TCB address inserted at the end of a linked list of tasks waiting for the same resource
(tasks are linked by tcb.locklink). The linked list is also part of the semaphore
structure, which has three elements.
semaphore input
is either allocation of the semaphore in global memory, or a pointer to the
semaphore to be allocated in global or extended memory. All three elements of
the semaphore array must be equal to 0 at the time of call.
Variable Name Description Contents
sem.semowner Current owner of
semaphore
0 if semaphore is available; owner’s TCB if
semaphore is owned
sem.semhead Head of the wait list Address of SEMHEAD if no tasks are
waiting; otherwise, first waiter’s TCB
address
sem.semtail Tail of the wait list Address of SEMHEAD if no tasks are
waiting; otherwise, last waiter’s TCB
address
CALL INIT^SEM ( semaphore ); !
i
INT:ref:3 (Semaphore in global memory)
INT(32) .EXT:ref (Pointer to semaphore in extended memory)
Caution. In general, the dynamic allocation of extended memory (with an extended pointer, for
example) should be avoided in USCODE because the TAL compiler would allocate such space
in extended segment ID 1024. Segment ID 1024 is reserved for TSCODE.