home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Papers / C++ Exceptions / µShell / Threads Support / ThreadSupport.h < prev   
Encoding:
C/C++ Source or Header  |  1998-06-02  |  1.5 KB  |  81 lines  |  [TEXT/CWIE]

  1. #ifndef __THREADSUPPORT__
  2. #define __THREADSUPPORT__
  3. #pragma once
  4.  
  5. #include "ToolBox.h"
  6. #include "ThreadContext.h"
  7.  
  8. #include <Threads.h>
  9.  
  10. #ifdef    __MWERKS__
  11.  
  12.     // set to a non-zero value to get profiling functions
  13.     #ifndef CW_THREAD_PROFILE
  14.     #define CW_THREAD_PROFILE        0
  15.     #endif
  16.  
  17.     #if __MWERKS__ >= 0x0800
  18.         #define CW7_EXCEPTIONS 0
  19.     #else
  20.         #define CW7_EXCEPTIONS 1
  21.     #endif
  22.  
  23.     #if !THREAD_ZEROOVERHEAD_EXCEPTIONS
  24.     #include <MWException.h>
  25.     #endif
  26.  
  27. #endif
  28.  
  29.  
  30.  
  31. class TThread : private ListLink
  32. {
  33. protected:
  34.     friend class ThreadContext;
  35.  
  36.     ThreadID                    fThreadID;
  37.     LinkedListOf<ThreadContext>    fContextList;
  38.  
  39. #if !GENERATINGCFM
  40.     long                        fSavedA5;
  41. #endif
  42.  
  43. #if CW_THREAD_PROFILE
  44.     ProfilerRefT                fProfilerRef;    // Profiler context
  45. #endif
  46.  
  47. #if CW7_EXCEPTIONS
  48.     ExceptionState                fExceptionState;
  49.     char                        fCatchBuffer[CATCH_BUFSIZE];
  50. #endif
  51.  
  52. public:
  53.                     TThread(ThreadID id);
  54.     virtual            ~TThread();
  55.  
  56.     virtual void    SwitchIn(void);
  57.     virtual void    SwitchOut(void);
  58.     virtual void    Terminate(void);
  59.     
  60. protected:
  61.     static pascal void SwitchInProc(ThreadID threadBeingSwitched, void *switchProcParam);
  62.     static pascal void SwitchOutProc(ThreadID threadBeingSwitched, void *switchProcParam);
  63.     static pascal void TerminationProc(ThreadID threadTerminated, void *terminationProcParam);
  64.  
  65.  
  66. public:
  67.     static TThread*    GetThreadHandler(ThreadID aThreadID);
  68.  
  69.     static LinkedListOf<TThread> fgThreadList;    // Global thread list
  70.  
  71. private: // required overrides for TListLink 
  72.     void*            GetObjectPtr();
  73. };
  74.  
  75.  
  76.  
  77.  
  78.  
  79. #endif // __THREADSUPPORT__
  80.  
  81.