ThreadContext.hpp
#if !defined(__THREADCONTEXT_HPP)
#define __THREADCONTEXT_HPP
/*
CoreLinux++
Copyright (C) 1999,2000 CoreLinux Consortium
The CoreLinux++ Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The CoreLinux++ Library Library is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#if !defined(__COMMON_HPP)
#include <Common.hpp>
#endif
#if !defined(__THREADEXCEPTION_HPP)
#include <ThreadException.hpp>
#endif
namespace corelinux
{
enum ThreadState
{
THREAD_WAITING_TO_START = 0,
THREAD_STARTING,
THREAD_RUNNING,
THREAD_NORMAL_EXIT,
THREAD_START_EXCEPTION,
THREAD_EXCEPTION,
THREAD_START_FAILED
};
DECLARE_CLASS( ThreadContext );
typedef int (*CallerFunctionPtr)(ThreadContextPtr);
typedef Int (*ThreadFrameFunctionPtr)( ThreadContextPtr );
typedef ThreadContextPtr (*ThreadContextCreatePtr)( ThreadContextRef );
typedef void (*ThreadContextDestroyPtr)( ThreadContextPtr );
typedef BytePtr (*ThreadStackCreatePtr)( ThreadContextPtr );
typedef void (*ThreadStackDestroyPtr)( BytePtr );
class ThreadContext : public Synchronized
{
public:
//
// Constructors and destructor
//
ThreadContext( CallerFunctionPtr )
throw ( Assertion );
ThreadContext( CallerFunctionPtr, Size )
throw ( Assertion );
ThreadContext( ThreadContextCref )
// throw ( ThreadNotWaitingException, Assertion );
throw ( Assertion );
virtual ~ThreadContext( void );
//
// Operator overloads
//
ThreadContextRef operator=( ThreadContextCref )
throw( Assertion );
bool operator==( ThreadContextCref ) const;
bool operator==( ThreadIdentifierCref ) const;
bool operator==( CallerFunctionPtr ) const;
operator ThreadIdentifierCref( void ) const;
//
// Accessors
//
const ThreadState & getState( void ) const;
Size getStackSize( void ) const;
Int getShareMask( void ) const;
Int getReturnCode( void ) const;
ThreadIdentifierCref getIdentifier( void ) const;
virtual ThreadFrameFunctionPtr getFramePointer( void );
BytePtr getStack( void );
BytePtr *getStackTop( void );
//
// Mutators
//
void setShareMask( Int );
void setFrameFunction( ThreadFrameFunctionPtr );
void setContextFunctions
(
ThreadContextCreatePtr ,
ThreadContextDestroyPtr
);
void setStackFunctions
(
ThreadStackCreatePtr ,
ThreadStackDestroyPtr
);
void setReturnCode( Int );
void setThreadState( ThreadState );
static Int cloneFrameFunction( ThreadContextPtr );
//
// Factory invocations
//
ThreadContextPtr createContext( void )
throw ( ThreadException );
void destroyContext( ThreadContextPtr ) throw ( Assertion );
protected:
//
// Constructors
//
ThreadContext( void ) throw ( Assertion );
//
// Operator overloads
//
ThreadContextRef operator=( ThreadIdentifier );
//
// Accessors
//
CallerFunctionPtr getCallerFunction( void );
private:
//
// Mutators
//
static Int defaultFrameFunction( ThreadContextPtr );
//
// Factory methods
//
static ThreadContextPtr defaultContextCreate( ThreadContextRef );
static void defaultContextDestroy( ThreadContextPtr );
static BytePtr defaultStackCreate( ThreadContextPtr );
static void defaultStackDestroy( BytePtr );
private:
static ThreadFrameFunctionPtr theDefaultFrameFunction;
static ThreadContextCreatePtr theDefaultContextCreator;
static ThreadContextDestroyPtr theDefaultContextDestroyer;
static ThreadStackCreatePtr theDefaultStackCreator;
static ThreadStackDestroyPtr theDefaultStackDestroyer;
ThreadFrameFunctionPtr theFrameFunction;
ThreadContextCreatePtr theContextCreator;
ThreadContextDestroyPtr theContextDestroyer;
ThreadStackCreatePtr theStackCreator;
ThreadStackDestroyPtr theStackDestroyer;
BytePtr theStack;
Size theStackSize;
Int theShareMask;
ThreadIdentifier theThreadIdentifier;
CallerFunctionPtr theCallersFunction;
ThreadState theThreadState;
Int theReturnCode;
};
}
#endif // if !defined(__THREADCONTEXT_HPP)
/*
Common rcs information do not modify
$Author: prudhomm $
$Revision: 1.1 $
$Date: 2000/04/23 20:43:13 $
$Locker: $
*/
corelinux::THREAD_RUNNING
The thread is running.
Definition: ThreadContext.hpp:49
corelinux::ThreadException
ThreadException is the base exception type for Thread.
Definition: ThreadException.hpp:39
corelinux::ThreadFrameFunctionPtr
Int(* ThreadFrameFunctionPtr)(ThreadContextPtr)
Thread frame entry point function handler.
Definition: ThreadContext.hpp:86
corelinux::ThreadContext::getShareMask
Int getShareMask(void) const
Get the share mask for the thread which determines VM, FILES, FILESYSTEM, SIGNAL shares.
Definition: ThreadContext.cpp:332
corelinux::ThreadContext::cloneFrameFunction
static Int cloneFrameFunction(ThreadContextPtr)
The definitive thread frame entry point.
Definition: ThreadContext.cpp:519
corelinux::ThreadContext::getIdentifier
ThreadIdentifierCref getIdentifier(void) const
Get the identifier for the thread.
Definition: ThreadContext.cpp:311
corelinux::THREAD_START_FAILED
Thread never started.
Definition: ThreadContext.hpp:65
corelinux::THREAD_WAITING_TO_START
The thread is waiting to be started.
Definition: ThreadContext.hpp:41
corelinux::ThreadContext::getCallerFunction
CallerFunctionPtr getCallerFunction(void)
Return the function pointer of the callers thread routine.
Definition: ThreadContext.cpp:318
corelinux::ThreadContext::setReturnCode
void setReturnCode(Int)
Set the return code for the thread.
Definition: ThreadContext.cpp:373
corelinux::ThreadContext
ThreadContext describes the context in which the thread operates.
Definition: ThreadContext.hpp:137
corelinux::ThreadContext::getStackTop
BytePtr * getStackTop(void)
Get the top of stack pointer.
Definition: ThreadContext.cpp:346
corelinux::ThreadContext::setContextFunctions
void setContextFunctions(ThreadContextCreatePtr, ThreadContextDestroyPtr)
Allows the caller to substitute the routines which create and destroy the managed ThreadContext objec...
Definition: ThreadContext.cpp:407
corelinux
Forward reference the various common classes.
Definition: AbstractAllocator.hpp:32
corelinux::ThreadContext::ThreadContext
ThreadContext(void)
Default constructor throws NEVER_GET_HERE.
Definition: ThreadContext.cpp:81
corelinux::ThreadState
ThreadState
Thread state enumeration.
Definition: ThreadContext.hpp:37
corelinux::ThreadContextDestroyPtr
void(* ThreadContextDestroyPtr)(ThreadContextPtr)
Managed ThreadContext deallocate function.
Definition: ThreadContext.hpp:108
corelinux::ThreadContext::setShareMask
void setShareMask(Int)
Change the sharing mask for the thread.
Definition: ThreadContext.cpp:359
corelinux::ThreadContext::operator=
ThreadContextRef operator=(ThreadContextCref)
Assignment operator changes the context.
Definition: ThreadContext.cpp:238
corelinux::THREAD_START_EXCEPTION
Thread never started with exception.
Definition: ThreadContext.hpp:57
corelinux::ThreadContext::getFramePointer
virtual ThreadFrameFunctionPtr getFramePointer(void)
Get the thread frame function pointer.
Definition: ThreadContext.cpp:352
corelinux::ThreadContext::operator==
bool operator==(ThreadContextCref) const
Equality operator compares contexts.
Definition: ThreadContext.cpp:269
corelinux::THREAD_NORMAL_EXIT
Thread completed without exception.
Definition: ThreadContext.hpp:53
corelinux::ThreadContext::getStack
BytePtr getStack(void)
Get the stack pointer.
Definition: ThreadContext.cpp:339
corelinux::ThreadStackCreatePtr
BytePtr(* ThreadStackCreatePtr)(ThreadContextPtr)
Managed ThreadContext stack creation function.
Definition: ThreadContext.hpp:118
corelinux::ThreadContext::destroyContext
void destroyContext(ThreadContextPtr)
Destroys the context instance.
Definition: ThreadContext.cpp:500
corelinux::ThreadContextCreatePtr
ThreadContextPtr(* ThreadContextCreatePtr)(ThreadContextRef)
Managed ThreadContext creation function.
Definition: ThreadContext.hpp:97
corelinux::ThreadContext::getStackSize
Size getStackSize(void) const
Get the size of the stack as defined by the context constructor.
Definition: ThreadContext.cpp:325
corelinux::ThreadContext::setThreadState
void setThreadState(ThreadState)
Set the state for the thread.
Definition: ThreadContext.cpp:366
corelinux::Assertion
Assertion is-a Exception created when an assertion fails.
Definition: Assertion.hpp:423
corelinux::Synchronized
Synchronized is a mixin which allows class objects to enable monitor functionality.
Definition: Synchronized.hpp:41
corelinux::ThreadStackDestroyPtr
void(* ThreadStackDestroyPtr)(BytePtr)
Managed ThreadContext stack deallocate function.
Definition: ThreadContext.hpp:129
corelinux::ThreadContext::createContext
ThreadContextPtr createContext(void)
Create a instance of ourself, we also invoke the create stack method so the instance is ready to be u...
Definition: ThreadContext.cpp:460
corelinux::ThreadContext::getState
const ThreadState & getState(void) const
Get the state of the thread as reflected in its context.
Definition: ThreadContext.cpp:297
corelinux::CallerFunctionPtr
int(* CallerFunctionPtr)(ThreadContextPtr)
Callers function entry point.
Definition: ThreadContext.hpp:78
corelinux::ThreadContext::setFrameFunction
void setFrameFunction(ThreadFrameFunctionPtr)
Allows the caller to substitute the thread frame entry point.
Definition: ThreadContext.cpp:380
corelinux::THREAD_EXCEPTION
Thread has died with exception.
Definition: ThreadContext.hpp:61
corelinux::ThreadContext::~ThreadContext
virtual ~ThreadContext(void)
Virtual destructor.
Definition: ThreadContext.cpp:216
corelinux::THREAD_STARTING
The thread is in the process of starting.
Definition: ThreadContext.hpp:45
corelinux::ThreadContext::setStackFunctions
void setStackFunctions(ThreadStackCreatePtr, ThreadStackDestroyPtr)
Allows the caller to substitute the routines which create and destroy the managed ThreadContext stack...
Definition: ThreadContext.cpp:434
corelinux::ThreadContext::getReturnCode
Int getReturnCode(void) const
Return the code returned by the callers function.
Definition: ThreadContext.cpp:304

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