CoreLinux++  0.4.32
ThreadContext.hpp
1 #if !defined(__THREADCONTEXT_HPP)
2 #define __THREADCONTEXT_HPP
3 
4 /*
5  CoreLinux++
6  Copyright (C) 1999,2000 CoreLinux Consortium
7 
8  The CoreLinux++ Library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version.
12 
13  The CoreLinux++ Library Library is distributed in the hope that it will
14  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public
19  License along with the GNU C Library; see the file COPYING.LIB. If not,
20  write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA 02111-1307, USA.
22 */
23 
24 #if !defined(__COMMON_HPP)
25 #include <Common.hpp>
26 #endif
27 
28 #if !defined(__THREADEXCEPTION_HPP)
29 #include <ThreadException.hpp>
30 #endif
31 
32 namespace corelinux
33 {
34 
36 
38  {
40 
42 
44 
46 
48 
50 
52 
54 
56 
58 
60 
62 
64 
66 
67  };
68 
69 
70  DECLARE_CLASS( ThreadContext );
71 
79 
87 
98 
109 
118  typedef BytePtr (*ThreadStackCreatePtr)( ThreadContextPtr );
119 
129  typedef void (*ThreadStackDestroyPtr)( BytePtr );
130 
138  {
139 
140  public:
141 
142  //
143  // Constructors and destructor
144  //
145 
157  throw ( Assertion );
158 
172  throw ( Assertion );
173 
184  // throw ( ThreadNotWaitingException, Assertion );
185  throw ( Assertion );
186 
188 
189  virtual ~ThreadContext( void );
190 
191  //
192  // Operator overloads
193  //
194 
205  throw( Assertion );
206 
213  bool operator==( ThreadContextCref ) const;
214 
221  bool operator==( ThreadIdentifierCref ) const;
222 
229  bool operator==( CallerFunctionPtr ) const;
230 
235  operator ThreadIdentifierCref( void ) const;
236  //
237  // Accessors
238  //
239 
246  const ThreadState & getState( void ) const;
247 
254  Size getStackSize( void ) const;
255 
263  Int getShareMask( void ) const;
264 
273  Int getReturnCode( void ) const;
274 
281  ThreadIdentifierCref getIdentifier( void ) const;
282 
289  virtual ThreadFrameFunctionPtr getFramePointer( void );
290 
292 
293  BytePtr getStack( void );
294 
296 
297  BytePtr *getStackTop( void );
298 
299  //
300  // Mutators
301  //
302 
311  void setShareMask( Int );
312 
323 
340  (
343  );
344 
360  void setStackFunctions
361  (
364  );
365 
366 
372  void setReturnCode( Int );
373 
379  void setThreadState( ThreadState );
380 
388  static Int cloneFrameFunction( ThreadContextPtr );
389 
390  //
391  // Factory invocations
392  //
393 
404  throw ( ThreadException );
405 
413  void destroyContext( ThreadContextPtr ) throw ( Assertion );
414 
415  protected:
416 
417  //
418  // Constructors
419  //
421 
422  ThreadContext( void ) throw ( Assertion );
423 
424  //
425  // Operator overloads
426  //
427 
436  ThreadContextRef operator=( ThreadIdentifier );
437 
438  //
439  // Accessors
440  //
441 
449 
450  private:
451 
452  //
453  // Mutators
454  //
455 
465  static Int defaultFrameFunction( ThreadContextPtr );
466 
467  //
468  // Factory methods
469  //
470 
479  static ThreadContextPtr defaultContextCreate( ThreadContextRef );
480 
486  static void defaultContextDestroy( ThreadContextPtr );
487 
494  static BytePtr defaultStackCreate( ThreadContextPtr );
495 
501  static void defaultStackDestroy( BytePtr );
502 
503 
504  private:
505 
507 
508  static ThreadFrameFunctionPtr theDefaultFrameFunction;
509 
511 
512  static ThreadContextCreatePtr theDefaultContextCreator;
513 
515 
516  static ThreadContextDestroyPtr theDefaultContextDestroyer;
517 
519 
520  static ThreadStackCreatePtr theDefaultStackCreator;
521 
523 
524  static ThreadStackDestroyPtr theDefaultStackDestroyer;
525 
527 
528  ThreadFrameFunctionPtr theFrameFunction;
529 
531 
532  ThreadContextCreatePtr theContextCreator;
533 
535 
536  ThreadContextDestroyPtr theContextDestroyer;
537 
539 
540  ThreadStackCreatePtr theStackCreator;
541 
543 
544  ThreadStackDestroyPtr theStackDestroyer;
545 
547 
548  BytePtr theStack;
549 
551 
552  Size theStackSize;
553 
555 
556  Int theShareMask;
557 
559 
560  ThreadIdentifier theThreadIdentifier;
561 
563 
564  CallerFunctionPtr theCallersFunction;
565 
567 
568  ThreadState theThreadState;
569 
571 
572  Int theReturnCode;
573  };
574 
575 }
576 
577 #endif // if !defined(__THREADCONTEXT_HPP)
578 
579 /*
580  Common rcs information do not modify
581  $Author: prudhomm $
582  $Revision: 1.1 $
583  $Date: 2000/04/23 20:43:13 $
584  $Locker: $
585 */
586 
The thread is running.
Definition: ThreadContext.hpp:49
ThreadException is the base exception type for Thread.
Definition: ThreadException.hpp:39
Int getShareMask(void) const
Get the share mask for the thread which determines VM, FILES, FILESYSTEM, SIGNAL shares.
Definition: ThreadContext.cpp:332
static Int cloneFrameFunction(ThreadContextPtr)
The definitive thread frame entry point.
Definition: ThreadContext.cpp:519
ThreadIdentifierCref getIdentifier(void) const
Get the identifier for the thread.
Definition: ThreadContext.cpp:311
Thread never started.
Definition: ThreadContext.hpp:65
The thread is waiting to be started.
Definition: ThreadContext.hpp:41
CallerFunctionPtr getCallerFunction(void)
Return the function pointer of the callers thread routine.
Definition: ThreadContext.cpp:318
ThreadContextPtr(* ThreadContextCreatePtr)(ThreadContextRef)
Managed ThreadContext creation function.
Definition: ThreadContext.hpp:97
void setReturnCode(Int)
Set the return code for the thread.
Definition: ThreadContext.cpp:373
Int(* ThreadFrameFunctionPtr)(ThreadContextPtr)
Thread frame entry point function handler.
Definition: ThreadContext.hpp:86
ThreadContext describes the context in which the thread operates.
Definition: ThreadContext.hpp:137
void(* ThreadContextDestroyPtr)(ThreadContextPtr)
Managed ThreadContext deallocate function.
Definition: ThreadContext.hpp:108
BytePtr * getStackTop(void)
Get the top of stack pointer.
Definition: ThreadContext.cpp:346
int(* CallerFunctionPtr)(ThreadContextPtr)
Callers function entry point.
Definition: ThreadContext.hpp:78
void setContextFunctions(ThreadContextCreatePtr, ThreadContextDestroyPtr)
Allows the caller to substitute the routines which create and destroy the managed ThreadContext objec...
Definition: ThreadContext.cpp:407
Forward reference the various common classes.
Definition: AbstractAllocator.hpp:32
ThreadContext(void)
Default constructor throws NEVER_GET_HERE.
Definition: ThreadContext.cpp:81
ThreadState
Thread state enumeration.
Definition: ThreadContext.hpp:37
void setShareMask(Int)
Change the sharing mask for the thread.
Definition: ThreadContext.cpp:359
ThreadContextRef operator=(ThreadContextCref)
Assignment operator changes the context.
Definition: ThreadContext.cpp:238
Thread never started with exception.
Definition: ThreadContext.hpp:57
virtual ThreadFrameFunctionPtr getFramePointer(void)
Get the thread frame function pointer.
Definition: ThreadContext.cpp:352
bool operator==(ThreadContextCref) const
Equality operator compares contexts.
Definition: ThreadContext.cpp:269
Thread completed without exception.
Definition: ThreadContext.hpp:53
BytePtr getStack(void)
Get the stack pointer.
Definition: ThreadContext.cpp:339
void destroyContext(ThreadContextPtr)
Destroys the context instance.
Definition: ThreadContext.cpp:500
Size getStackSize(void) const
Get the size of the stack as defined by the context constructor.
Definition: ThreadContext.cpp:325
void setThreadState(ThreadState)
Set the state for the thread.
Definition: ThreadContext.cpp:366
Assertion is-a Exception created when an assertion fails.
Definition: Assertion.hpp:423
Synchronized is a mixin which allows class objects to enable monitor functionality.
Definition: Synchronized.hpp:41
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
const ThreadState & getState(void) const
Get the state of the thread as reflected in its context.
Definition: ThreadContext.cpp:297
void setFrameFunction(ThreadFrameFunctionPtr)
Allows the caller to substitute the thread frame entry point.
Definition: ThreadContext.cpp:380
BytePtr(* ThreadStackCreatePtr)(ThreadContextPtr)
Managed ThreadContext stack creation function.
Definition: ThreadContext.hpp:118
Thread has died with exception.
Definition: ThreadContext.hpp:61
virtual ~ThreadContext(void)
Virtual destructor.
Definition: ThreadContext.cpp:216
void(* ThreadStackDestroyPtr)(BytePtr)
Managed ThreadContext stack deallocate function.
Definition: ThreadContext.hpp:129
The thread is in the process of starting.
Definition: ThreadContext.hpp:45
void setStackFunctions(ThreadStackCreatePtr, ThreadStackDestroyPtr)
Allows the caller to substitute the routines which create and destroy the managed ThreadContext stack...
Definition: ThreadContext.cpp:434
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