Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Examples

ThreadContext.hpp

00001 #if !defined(__THREADCONTEXT_HPP) 00002 #define __THREADCONTEXT_HPP 00003 00004 /* 00005 CoreLinux++ 00006 Copyright (C) 1999,2000 CoreLinux Consortium 00007 00008 The CoreLinux++ Library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Library General Public License as 00010 published by the Free Software Foundation; either version 2 of the 00011 License, or (at your option) any later version. 00012 00013 The CoreLinux++ Library Library is distributed in the hope that it will 00014 be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Library General Public License for more details. 00017 00018 You should have received a copy of the GNU Library General Public 00019 License along with the GNU C Library; see the file COPYING.LIB. If not, 00020 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00021 Boston, MA 02111-1307, USA. 00022 */ 00023 00024 #if !defined(__COMMON_HPP) 00025 #include <Common.hpp> 00026 #endif 00027 00028 #if !defined(__THREADEXCEPTION_HPP) 00029 #include <ThreadException.hpp> 00030 #endif 00031 00032 namespace corelinux 00033 { 00034 00036 00037 enum ThreadState 00038 { 00040 00041 THREAD_WAITING_TO_START = 0, 00042 00044 00045 THREAD_STARTING, 00046 00048 00049 THREAD_RUNNING, 00050 00052 00053 THREAD_NORMAL_EXIT, 00054 00056 00057 THREAD_START_EXCEPTION, 00058 00060 00061 THREAD_EXCEPTION, 00062 00064 00065 THREAD_START_FAILED 00066 00067 }; 00068 00069 00070 DECLARE_CLASS( ThreadContext ); 00071 00078 typedef int (*CallerFunctionPtr)(ThreadContextPtr); 00079 00086 typedef Int (*ThreadFrameFunctionPtr)( ThreadContextPtr ); 00087 00097 typedef ThreadContextPtr (*ThreadContextCreatePtr)( ThreadContextRef ); 00098 00108 typedef void (*ThreadContextDestroyPtr)( ThreadContextPtr ); 00109 00118 typedef BytePtr (*ThreadStackCreatePtr)( ThreadContextPtr ); 00119 00129 typedef void (*ThreadStackDestroyPtr)( BytePtr ); 00130 00137 class ThreadContext : public Synchronized 00138 { 00139 00140 public: 00141 00142 // 00143 // Constructors and destructor 00144 // 00145 00156 ThreadContext( CallerFunctionPtr ) 00157 throw ( Assertion ); 00158 00171 ThreadContext( CallerFunctionPtr, Size ) 00172 throw ( Assertion ); 00173 00183 ThreadContext( ThreadContextCref ) 00184 // throw ( ThreadNotWaitingException, Assertion ); 00185 throw ( Assertion ); 00186 00188 00189 virtual ~ThreadContext( void ); 00190 00191 // 00192 // Operator overloads 00193 // 00194 00204 ThreadContextRef operator=( ThreadContextCref ) 00205 throw( Assertion ); 00206 00213 bool operator==( ThreadContextCref ) const; 00214 00221 bool operator==( ThreadIdentifierCref ) const; 00222 00229 bool operator==( CallerFunctionPtr ) const; 00230 00235 operator ThreadIdentifierCref( void ) const; 00236 // 00237 // Accessors 00238 // 00239 00246 const ThreadState & getState( void ) const; 00247 00254 Size getStackSize( void ) const; 00255 00263 Int getShareMask( void ) const; 00264 00273 Int getReturnCode( void ) const; 00274 00281 ThreadIdentifierCref getIdentifier( void ) const; 00282 00289 virtual ThreadFrameFunctionPtr getFramePointer( void ); 00290 00292 00293 BytePtr getStack( void ); 00294 00296 00297 BytePtr *getStackTop( void ); 00298 00299 // 00300 // Mutators 00301 // 00302 00311 void setShareMask( Int ); 00312 00322 void setFrameFunction( ThreadFrameFunctionPtr ); 00323 00339 void setContextFunctions 00340 ( 00341 ThreadContextCreatePtr , 00342 ThreadContextDestroyPtr 00343 ); 00344 00360 void setStackFunctions 00361 ( 00362 ThreadStackCreatePtr , 00363 ThreadStackDestroyPtr 00364 ); 00365 00366 00372 void setReturnCode( Int ); 00373 00379 void setThreadState( ThreadState ); 00380 00388 static Int cloneFrameFunction( ThreadContextPtr ); 00389 00390 // 00391 // Factory invocations 00392 // 00393 00403 ThreadContextPtr createContext( void ) 00404 throw ( ThreadException ); 00405 00413 void destroyContext( ThreadContextPtr ) throw ( Assertion ); 00414 00415 protected: 00416 00417 // 00418 // Constructors 00419 // 00421 00422 ThreadContext( void ) throw ( Assertion ); 00423 00424 // 00425 // Operator overloads 00426 // 00427 00436 ThreadContextRef operator=( ThreadIdentifier ); 00437 00438 // 00439 // Accessors 00440 // 00441 00448 CallerFunctionPtr getCallerFunction( void ); 00449 00450 private: 00451 00452 // 00453 // Mutators 00454 // 00455 00465 static Int defaultFrameFunction( ThreadContextPtr ); 00466 00467 // 00468 // Factory methods 00469 // 00470 00479 static ThreadContextPtr defaultContextCreate( ThreadContextRef ); 00480 00486 static void defaultContextDestroy( ThreadContextPtr ); 00487 00494 static BytePtr defaultStackCreate( ThreadContextPtr ); 00495 00501 static void defaultStackDestroy( BytePtr ); 00502 00503 00504 private: 00505 00507 00508 static ThreadFrameFunctionPtr theDefaultFrameFunction; 00509 00511 00512 static ThreadContextCreatePtr theDefaultContextCreator; 00513 00515 00516 static ThreadContextDestroyPtr theDefaultContextDestroyer; 00517 00519 00520 static ThreadStackCreatePtr theDefaultStackCreator; 00521 00523 00524 static ThreadStackDestroyPtr theDefaultStackDestroyer; 00525 00527 00528 ThreadFrameFunctionPtr theFrameFunction; 00529 00531 00532 ThreadContextCreatePtr theContextCreator; 00533 00535 00536 ThreadContextDestroyPtr theContextDestroyer; 00537 00539 00540 ThreadStackCreatePtr theStackCreator; 00541 00543 00544 ThreadStackDestroyPtr theStackDestroyer; 00545 00547 00548 BytePtr theStack; 00549 00551 00552 Size theStackSize; 00553 00555 00556 Int theShareMask; 00557 00559 00560 ThreadIdentifier theThreadIdentifier; 00561 00563 00564 CallerFunctionPtr theCallersFunction; 00565 00567 00568 ThreadState theThreadState; 00569 00571 00572 Int theReturnCode; 00573 }; 00574 00575 } 00576 00577 #endif // if !defined(__THREADCONTEXT_HPP) 00578 00579 /* 00580 Common rcs information do not modify 00581 $Author: prudhomm $ 00582 $Revision: 1.1 $ 00583 $Date: 2000/04/23 20:43:13 $ 00584 $Locker: $ 00585 */ 00586

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