User-Level Native Thread Primitives (GThread) Library White Paper (G06.26+)
User-Level Native Thread Primitives (GThread Library) 03/31/2005
Hewlett-Packard Company--540065-001 Page 20 of 46
GTH_ STACK_CHECK_ACTIVE_( GThread_CB cb, int32 stack_delta )
Description:
Permits a client to determine whether there is a specified amount of stack space available on an
active static thread using the current stack pointers. Callable only for a static thread. This replaces
accessing the thread control block elements StackSize, StackOrigin, and then performing a check
against the current value of the stack pointer (sp).
Input:
cb - The address of the currently active thread control block.
stack_delta - An indication of how much bigger the mem stack could potentially grow, in bytes.
Return: int16
Returns zero if there is available stack space.
Returns nonzero if:
• The thread model is swapped
• The stack space wasn’t allocated
• A negative stack_delta was supplied
• There is insufficient stack space available after applying stack_delta
Considerations:
This interface applies stack_delta to the current stack pointer, and compares the resulting value to
the stack area allocated. If the resulting value is outside the allocated area, this interface returns an
indication that there is insufficient stack space. A value of zero for stack_delta is valid; it results in
a check to see if the stack is currently in an overflow condition.
On TNS/E native platforms both the reg and mem stacks are checked. stack_delta is treated as the
memory ‘stack delta’ and a reg ‘stack delta’ is implicitly calculated from stack_delta. The implicit
calculation is based on the ‘ratio’ of mem stack to reg stack size that was established for the
specified thread at initialization time – refer to Section 3.6.2 for more details.
This routine requires the thread control block of the currently active thread to perform the check,
provided that a suspended thread control block to this interface results in an invalid comparison.