CoreLinux++  0.4.32
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
corelinux::ThreadContext Class Reference

ThreadContext describes the context in which the thread operates. More...

#include <ThreadContext.hpp>

Public Member Functions

 ThreadContext (CallerFunctionPtr) throw ( Assertion )
 Default constructor only requires a caller entry point function. More...
 
 ThreadContext (CallerFunctionPtr, Size) throw ( Assertion )
 Constructor which allows the caller to define the stack. More...
 
 ThreadContext (ThreadContextCref) throw ( Assertion )
 Copy constructor takes information from the context argument. More...
 
virtual ~ThreadContext (void)
 Virtual destructor.
 
ThreadContextRef operator= (ThreadContextCref) throw ( Assertion )
 Assignment operator changes the context. More...
 
bool operator== (ThreadContextCref) const
 Equality operator compares contexts. More...
 
bool operator== (ThreadIdentifierCref) const
 Equality matches the thread identifiers. More...
 
bool operator== (CallerFunctionPtr) const
 Equality operator matches the callers function. More...
 
 operator ThreadIdentifierCref (void) const
 Coerces ThreadContext to ThreadIdentifier. More...
 
const ThreadStategetState (void) const
 Get the state of the thread as reflected in its context. More...
 
Size getStackSize (void) const
 Get the size of the stack as defined by the context constructor. More...
 
Int getShareMask (void) const
 Get the share mask for the thread which determines VM, FILES, FILESYSTEM, SIGNAL shares. More...
 
Int getReturnCode (void) const
 Return the code returned by the callers function. More...
 
ThreadIdentifierCref getIdentifier (void) const
 Get the identifier for the thread. More...
 
virtual ThreadFrameFunctionPtr getFramePointer (void)
 Get the thread frame function pointer. More...
 
BytePtr getStack (void)
 Get the stack pointer.
 
BytePtr * getStackTop (void)
 Get the top of stack pointer.
 
void setShareMask (Int)
 Change the sharing mask for the thread. More...
 
void setFrameFunction (ThreadFrameFunctionPtr)
 Allows the caller to substitute the thread frame entry point. More...
 
void setContextFunctions (ThreadContextCreatePtr, ThreadContextDestroyPtr)
 Allows the caller to substitute the routines which create and destroy the managed ThreadContext object. More...
 
void setStackFunctions (ThreadStackCreatePtr, ThreadStackDestroyPtr)
 Allows the caller to substitute the routines which create and destroy the managed ThreadContext stack object. More...
 
void setReturnCode (Int)
 Set the return code for the thread. More...
 
void setThreadState (ThreadState)
 Set the state for the thread. More...
 
ThreadContextPtr createContext (void) throw ( ThreadException )
 Create a instance of ourself, we also invoke the create stack method so the instance is ready to be used to run a thread. More...
 
void destroyContext (ThreadContextPtr) throw ( Assertion )
 Destroys the context instance. More...
 
- Public Member Functions inherited from corelinux::Synchronized
 Synchronized (void)
 Default constructor.
 
 Synchronized (SynchronizedCref)
 Copy constructor.
 
virtual ~Synchronized (void)
 Virtual Destructor.
 
SynchronizedRef operator= (SynchronizedCref)
 Assignment operator.
 
bool operator== (SynchronizedCref) const
 Equality operator.
 

Static Public Member Functions

static Int cloneFrameFunction (ThreadContextPtr)
 The definitive thread frame entry point. More...
 

Protected Member Functions

 ThreadContext (void) throw ( Assertion )
 Default constructor throws NEVER_GET_HERE.
 
ThreadContextRef operator= (ThreadIdentifier)
 Assignment operator for designating thread identity. More...
 
CallerFunctionPtr getCallerFunction (void)
 Return the function pointer of the callers thread routine. More...
 
- Protected Member Functions inherited from corelinux::Synchronized
Guard access (void) const throw (SemaphoreException)
 Access returns a instance of Guard which is block scoped to the caller. More...
 

Additional Inherited Members

- Protected Types inherited from corelinux::Synchronized
typedef GuardGuardPtr
 
typedef const GuardGuardCptr
 
typedef GuardGuardRef
 
typedef const GuardGuardCref
 

Detailed Description

ThreadContext describes the context in which the thread operates.

Included are stack resource, shared address space flags, factory methods, and state indicators.

Constructor & Destructor Documentation

corelinux::ThreadContext::ThreadContext ( CallerFunctionPtr  aFuncPtr)
throw (Assertion
)

Default constructor only requires a caller entry point function.

Defaults in effect are 8k stack which is allocated by the system, and all resources of the caller are shared by the new thread.

Parameters
CallerFunctionpointer to the callers thread routine.
Exceptions
Assertionif pointer is null

References corelinux::THREAD_WAITING_TO_START, and ThreadContext().

corelinux::ThreadContext::ThreadContext ( CallerFunctionPtr  aFuncPtr,
Size  aStackSize 
)
throw (Assertion
)

Constructor which allows the caller to define the stack.

All resources of the caller are shared by the new thread.

Parameters
CallerFunctionpointer to the callers thread routine.
SizeRequest size for stack in number of bytes.
Exceptions
Assertionif routine pointer is null or callers stack size is negative.

References corelinux::THREAD_WAITING_TO_START.

corelinux::ThreadContext::ThreadContext ( ThreadContextCref  aContext)
throw (Assertion
)

Copy constructor takes information from the context argument.

Parameters
ThreadContextreference to existing context
Exceptions
ThreadNotWaitingExceptionif the argument context is not in a THREAD_WAITING_TO_START state.

References corelinux::THREAD_WAITING_TO_START.

Member Function Documentation

Int corelinux::ThreadContext::cloneFrameFunction ( ThreadContextPtr  aPtr)
static

The definitive thread frame entry point.

This is the address that "clone" gets.

Parameters
ThreadContextpointer to a thread context
Returns
Int return code

References getCallerFunction(), getFramePointer(), getReturnCode(), getStackSize(), corelinux::Thread::getThreadIdentifier(), setReturnCode(), setThreadState(), corelinux::THREAD_EXCEPTION, corelinux::THREAD_NORMAL_EXIT, corelinux::THREAD_RUNNING, and ThreadContext().

Referenced by corelinux::Thread::startThread().

ThreadContextPtr corelinux::ThreadContext::createContext ( void  )
throw (ThreadException
)

Create a instance of ourself, we also invoke the create stack method so the instance is ready to be used to run a thread.

Returns
ThreadContext pointer to object.
Exceptions
ThreadAllocationExceptioneither for Stack or Context

References destroyContext().

Referenced by corelinux::Thread::startThread().

void corelinux::ThreadContext::destroyContext ( ThreadContextPtr  aContext)
throw (Assertion
)

Destroys the context instance.

A check is made to insure it is not a suicide.

Parameters
ThreadContextpointer to context to destroy
Exceptions
Assertionif self referenced

Referenced by createContext(), and corelinux::Thread::startThread().

CallerFunctionPtr corelinux::ThreadContext::getCallerFunction ( void  )
protected

Return the function pointer of the callers thread routine.

Returns
CallerFunctionPtr

Referenced by cloneFrameFunction().

ThreadFrameFunctionPtr corelinux::ThreadContext::getFramePointer ( void  )
virtual

Get the thread frame function pointer.

Returns
ThreadFrameFunctionPtr pointer to instance or default thread frame

Referenced by cloneFrameFunction().

ThreadIdentifierCref corelinux::ThreadContext::getIdentifier ( void  ) const

Get the identifier for the thread.

This is only valid once a thread is started

Returns
ThreadIdentifier the id

Referenced by corelinux::Thread::getThreadPriority(), and corelinux::Thread::setThreadPriority().

Int corelinux::ThreadContext::getReturnCode ( void  ) const

Return the code returned by the callers function.

This is only valid if the thread ended normally

Returns
Int return code
See also
ThreadState

Referenced by cloneFrameFunction().

Int corelinux::ThreadContext::getShareMask ( void  ) const

Get the share mask for the thread which determines VM, FILES, FILESYSTEM, SIGNAL shares.

Returns
Int

Referenced by corelinux::Thread::startThread().

Size corelinux::ThreadContext::getStackSize ( void  ) const

Get the size of the stack as defined by the context constructor.

Returns
Size in bytes

Referenced by cloneFrameFunction().

const ThreadState & corelinux::ThreadContext::getState ( void  ) const

Get the state of the thread as reflected in its context.

Returns
ThreadState

Referenced by corelinux::Thread::destroyThreadContext().

corelinux::ThreadContext::operator ThreadIdentifierCref ( void  ) const

Coerces ThreadContext to ThreadIdentifier.

Returns
ThreadIdentifier reference
ThreadContextRef corelinux::ThreadContext::operator= ( ThreadContextCref  aContext)
throw (Assertion
)

Assignment operator changes the context.

Parameters
ThreadContextreference to existing context
Returns
ThreadContext reference
Exceptions
ThreadNotWaitingExceptionif the argument context is not in a THREAD_WAITING_TO_START state.

References corelinux::THREAD_WAITING_TO_START.

ThreadContextRef corelinux::ThreadContext::operator= ( ThreadIdentifier  aIdentifier)
protected

Assignment operator for designating thread identity.

Parameters
ThreadIdentifieras retrieved from the OS
Returns
ThreadContext reference to self
bool corelinux::ThreadContext::operator== ( ThreadContextCref  aContext) const

Equality operator compares contexts.

Parameters
ThreadContextreference to existing context
Returns
bool true if same
bool corelinux::ThreadContext::operator== ( ThreadIdentifierCref  aIdentifier) const

Equality matches the thread identifiers.

Parameters
ThreadIdentifierreference to identifier
Returns
bool true if same
bool corelinux::ThreadContext::operator== ( CallerFunctionPtr  aFunction) const

Equality operator matches the callers function.

Parameters
CallerFunctionPtra function reference
Returns
bool true if same.
void corelinux::ThreadContext::setContextFunctions ( ThreadContextCreatePtr  aCreate,
ThreadContextDestroyPtr  aDestroy 
)

Allows the caller to substitute the routines which create and destroy the managed ThreadContext object.

The call to create the object comes in at the startThread prior to stack allocation, the call to destroy the object comes from startThread exception and error handling, or when requested by the caller.

Parameters
ThreadContextCreatePtrthe function pointer to set, If this argument is NULLPTR the default handlers are set for create and destroy.
ThreadContextDestroyPtrto the function pointer to set. If this argument is NULLPTR the default handlers are set for create and destroy.

References setStackFunctions().

Referenced by setFrameFunction().

void corelinux::ThreadContext::setFrameFunction ( ThreadFrameFunctionPtr  aFrame)

Allows the caller to substitute the thread frame entry point.

Parameters
ThreadFrameFunctionPtrpoints to the new frame function that is called when starting a thread. If this argument is NULLPTR the default handler is set.

References setContextFunctions().

void corelinux::ThreadContext::setReturnCode ( Int  aReturnCode)

Set the return code for the thread.

Parameters
Intreturn code value

Referenced by cloneFrameFunction(), and corelinux::Thread::startThread().

void corelinux::ThreadContext::setShareMask ( Int  aMask)

Change the sharing mask for the thread.

This is only effective when set prior to starting the thread.

Parameters
Intmask of values for thread resource sharing and signal disposition
void corelinux::ThreadContext::setStackFunctions ( ThreadStackCreatePtr  aCreate,
ThreadStackDestroyPtr  aDestroy 
)

Allows the caller to substitute the routines which create and destroy the managed ThreadContext stack object.

The call to create the stack object comes in at the startThread prior to threading, the call to destroy the object comes from startThread exception and error handling, or when the destruction of the ThreadContext is imanent.

Parameters
ThreadStackCreatePtrpointer to set. If this argument is NULLPTR the default handlers are set for create and destroy.
ThreadStackDestroyPtrthe function pointer to set. If this argument is NULLPTR the default handlers are set for create and destroy.

Referenced by setContextFunctions().

void corelinux::ThreadContext::setThreadState ( ThreadState  aState)

Set the state for the thread.

Parameters
ThreadStatethe threads new state

Referenced by cloneFrameFunction(), corelinux::Thread::setThreadPriority(), and corelinux::Thread::startThread().


The documentation for this class was generated from the following files:

This is the CoreLinux++ reference manual
Provided by The CoreLinux Consortium