User-Level Native Thread Primitives (GThread) Library White Paper (G06.27+, H06.03+, J06.03+)

User-Level Native Thread Primitives (GThread Library) 02/15/2012
540065-004 Page 21 of 44
an overflow condition existed at the time GTHREAD_SETJMP_ was called to capture stack pointer
information.
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 interface returns information based on the last call to GTHREAD_SETJMP_, or to
GTHREAD_INITIATE_ if GTHREAD_SETJMP_ has not yet been called. This interface is intended
for use on suspended threads. For an active thread, the results are accurate only within the function
that most recently called GTHREAD_SETJMP_.
GTH_STACK_CHECK_ACTIVE2_( GThread_CB cb, int32 mem_delta, int32 reg_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. May be called only for an unprotected static
thread. This replaces accessing the thread control block elements StackSize, StackOrigin, and
performing a check against the current value of the stack pointer (sp).
Input:
cb - The address of the currently active thread control block.
mem_delta - An indication of how much bigger the mem stack could potentially grow, in bytes.
reg_delta - An indication of how much bigger the reg stack could potentially grow, in bytes. This
argument is ignored on platforms other than TNS/E native.
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 mem_delta or reg_delta was supplied
There is insufficient stack space available after applying mem_delta and reg_delta
Considerations:
For TNS/E native platforms, this interface applies mem_delta to the current mem stack pointer and
reg_delta to the current reg stack pointer. The resulting values are compared to the stack area
allocated. If either of the resulting values is outside the allocated area, this routine returns that there
is insufficient stack space. A value of zero for mem_delta and/or reg_delta is valid; it results in a
check to see if the corresponding stack for the active thread is currently in an overflow condition.
For TNS and TNS/R, the contents of reg_delta are ignored and the routine functions in the same
manner as GTH_STACK_CHECK_ACTIVE_.
This routine requires the thread control block of the currently active thread to perform the check. An
invalid comparison results when a suspended thread control block is provided to this interface.