home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / IBMCLASS / ITHREAD.HPP < prev    next >
C/C++ Source or Header  |  1993-10-22  |  34KB  |  649 lines

  1. #ifndef _ITHREAD_
  2. #define _ITHREAD_
  3. /*******************************************************************************
  4. * FILE NAME: ithread.hpp                                                       *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the class(es):                                              *
  8. *     IThread         - Objects representing OS/2 threads of execution.        *
  9. *     IThreadFn       - Abstract "threadable function" class.                  *
  10. *     IThreadMemberFn - Template class for "threadable member function."       *
  11. *     ICurrentThread  - Additional functions that can only be applied to the   *
  12. *                       current thread of execution.                           *
  13. *                                                                              *
  14. * COPYRIGHT:                                                                   *
  15. *   Licensed Materials - Property of IBM                                       *
  16. *   (C) Copyright IBM Corporation 1992, 1993                                   *
  17. *   All Rights Reserved                                                        *
  18. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  19. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  20. *                                                                              *
  21. *******************************************************************************/
  22. #ifndef _IVBASE_
  23.   #include <ivbase.hpp>
  24. #endif
  25.  
  26. #ifndef _IREFCNT_
  27.   #include <irefcnt.hpp>
  28. #endif
  29.  
  30. #ifndef _IHANDLE_
  31.   #include <ihandle.hpp>
  32. #endif
  33.  
  34. #ifndef _IAPP_
  35.   #include <iapp.hpp>
  36. #endif
  37.  
  38. /*----------------------------------------------------------------------------*/
  39. /* Align classes on four byte boundary.                                       */
  40. /*----------------------------------------------------------------------------*/
  41. #pragma pack(4)
  42.  
  43. /*----------------------------------------------------------------------------*/
  44. /* Turn off warning for compiler generated copy/assignment                    */
  45. /*----------------------------------------------------------------------------*/
  46. #pragma info(nocpy)
  47.  
  48.  
  49. class IThreadFn : public IRefCounted {
  50. typedef IRefCounted
  51.   Inherited;
  52. /*******************************************************************************
  53. * The IThreadFn class is an abstract thread function class.                    *
  54. *                                                                              *
  55. * Objects of this class are used to represent functions to be dispatched on    *
  56. * secondary threads of execution when an IThread is started.  These objects    *
  57. * are reference counted to manage their destruction (after the thread has      *
  58. * terminated); a reference to such an IThreadFn is passed to IThread::start.   *
  59. *                                                                              *
  60. * See IThread for details on usage of this class.                              *
  61. *                                                                              *
  62. * Example:                                                                     *
  63. *                                                                              *
  64. *   class MyFunction : public IThreadFn {                                      *
  65. *   public:                                                                    *
  66. *   virtual void                                                               *
  67. *     run ( )                                                                  *
  68. *     {                                                                        *
  69. *     // Place your code here.                                                 *
  70. *     }                                                                        *
  71. *   };                                                                         *
  72. *   //...                                                                      *
  73. *   IThread newThread( new MyFunction );                                       *
  74. *******************************************************************************/
  75. public:
  76.   IThreadFn ( );
  77. virtual
  78.   ~IThreadFn ( );
  79.  
  80. /*---------------------------- Callback Function -------------------------------
  81. | The following function is a callback function:                               |
  82. |   run - Called when the thread function object is invoked.                   |
  83. ------------------------------------------------------------------------------*/
  84. virtual void
  85.   run ( ) = 0;
  86. }; // class IThreadFn
  87.  
  88. template < class T >
  89. class IThreadMemberFn : public IThreadFn {
  90. typedef IThreadFn
  91.   Inherited;
  92. /*******************************************************************************
  93. * The IThreadMemberFn template class is an IThreadFn derived class for         *
  94. * dispatching C++ member functions against an object on a new thread.  The     *
  95. * template argument is:                                                        *
  96. *                                                                              *
  97. *   T - The class of object against which the member functions will be         *
  98. *       applied.                                                               *
  99. *                                                                              *
  100. * Instances of this class are used to dispatch C++ member functions on a       *
  101. * separate thread.  The template argument is the class of the object for       *
  102. * which the functions are called.  The constructor for such objects requires   *
  103. * a reference to the object the member functions are to be applied to and a    *
  104. * pointer to the member functions.                                             *
  105. *                                                                              *
  106. * The member functions return void and accept no arguments.  Support for       *
  107. * other member functions can be added by subclassing this class.               *
  108. *                                                                              *
  109. * Example:                                                                     *
  110. *   class MyClass {                                                            *
  111. *   public:                                                                    *
  112. *   void job()                                                                 *
  113. *     {                                                                        *
  114. *     // Code to run on separate thread.                                       *
  115. *     }                                                                        *
  116. *   };                                                                         *
  117. *   //...                                                                      *
  118. *   MyClass myObj;                                                             *
  119. *   IThread thread;                                                            *
  120. *   thread.start( new IThreadMemberFn<MyClass>( myObj, MyClass::job ) );       *
  121. *******************************************************************************/
  122. public:
  123. /*------------------------------- Constructor ----------------------------------
  124. | The constructor requires an object of the template argument class T and a    |
  125. | pointer to a member function of that class (returning void and accepting no  |
  126. | arguments).                                                                  |
  127. ------------------------------------------------------------------------------*/
  128. IThreadMemberFn ( T &obj,
  129.                   void ( T :: *mem )( ) )
  130.   : member( mem ), object( obj )
  131.   {
  132.   }
  133.  
  134. /*-------------------------------- Overrides -----------------------------------
  135. | This class overrides the following inherited function:                       |
  136. |   run - Calls the pointed-to member function to the argument provided at     |
  137. |         construction.                                                        |
  138. ------------------------------------------------------------------------------*/
  139. virtual void
  140.   run ( )
  141.   {
  142.   (object.*member)();
  143.   }
  144.  
  145. private: /*------------------------ PRIVATE ----------------------------------*/
  146. T
  147.   &object;
  148. void ( T ::
  149.  *member )( );
  150. }; // IThreadMemberFn
  151.  
  152. class IStartedThread;
  153. class IWindowList;
  154. struct tib_s;
  155.  
  156. class ICurrentThread;
  157.  
  158. class IThread : public IVBase {
  159. typedef IVBase
  160.   Inherited;
  161. /*******************************************************************************
  162. * The IThread class's objects represent threads of execution within the        *
  163. * current program.  This class provides support for implementing multi-        *
  164. * threaded programs.  IThread objects provide access to all the tasking APIs   *
  165. * of the operating system.  In addition, these objects serve as the anchor     *
  166. * for thread-specific information (for example, the Presentation Manager       *
  167. * anchor block).                                                               *
  168. *                                                                              *
  169. * IThread objects are generally used in one of the following ways:             *
  170. *                                                                              *
  171. *    - To apply thread functions to the current thread.  In most cases, these  *
  172. *      functions will be applied to the IThread object reference returned by   *
  173. *      the static member IThread::current.                                     *
  174. *                                                                              *
  175. *    - To create additional threads of execution by instantiating new IThread  *
  176. *      objects and starting them.                                              *
  177. *                                                                              *
  178. *    - To manipulate threads of execution initiated using alternate means,     *
  179. *      and for which only the thread's ID is known.                            *
  180. *                                                                              *
  181. * EXAMPLE:                                                                     *
  182. *                                                                              *
  183. * // This is typical code appearing in main():                                 *
  184. * IThread::current().initializePM(); // Initialize PM environment.             *
  185. * // Create windows...                                                         *
  186. * IThread::current().processMsgs();  // Process window messages.               *
  187. * IThread::current().terminatePM();  // Terminate PM environment.              *
  188. *                                                                              *
  189. * // This is typical code to spawn a new thread to execute                     *
  190. * // member function foo() against the "this" object:                          *
  191. * IThread thread;                                                              *
  192. * thread.start( IThreadMemberFn< MyClass >( this, foo ) );                     *
  193. *                                                                              *
  194. * // This is typical code that operates on a thread with ID tid:               *
  195. * IThread thread( tid );                                                       *
  196. * thread.suspend();                                                            *
  197. * //...                                                                        *
  198. * thread.resume();                                                             *
  199. *******************************************************************************/
  200. public:
  201. /*------------------------------ Function Types --------------------------------
  202. | These typedefs define the two types of (non-member) functions that can       |
  203. | be dispatched on a separate thread:                                          |
  204. |   OptlinkFnPtr - Pointer to a function with _Optlink linkage.                |
  205. |   SystemFnPtr  - Pointer to a function with _System linkage.                 |
  206. ------------------------------------------------------------------------------*/
  207. typedef void ( _Optlink *OptlinkFnPtr ) ( void * );
  208. typedef void ( _System  *SystemFnPtr  ) ( unsigned long );
  209.  
  210. /*------------------------- Constructors/Destructor ----------------------------
  211. | You can construct instances of this class in the following ways:             |
  212. |                                                                              |
  213. |    - Using the default constructor.  The default constructor is used to      |
  214. |      build an IThread to be subsequently started using the start member      |
  215. |      function.                                                               |
  216. |                                                                              |
  217. |    - With specification of code to run.  This form of the constructor is     |
  218. |      used to construct a new IThread and immediately dispatch it.  It is     |
  219. |      equivalent to constructing using the default constructor and then       |
  220. |      dispatching the thread using start.                                     |
  221. |                                                                              |
  222. |      This constructor permits specification of whether or not the new        |
  223. |      thread is to be a Presentation Manager thread.  If it is, then          |
  224. |      initializePM is called automatically after the thread is started.       |
  225. |                                                                              |
  226. |    - From the thread ID of a previously started thread.  This constructor    |
  227. |      is used to provide IThread functionality to threads created using       |
  228. |      alternate means (either using  _beginthread or DosCreateThread).        |
  229. |                                                                              |
  230. | IThread has a virtual destructor that takes care of deallocating resources.  |
  231. |                                                                              |
  232. | NOTE: The destructor does not stop the thread.                               |
  233. |                                                                              |
  234. | Multi-threaded programs (those that invoke the start member function)        |
  235. | should be compiled with /Gm+ in order to avoid unresolved externals at link  |
  236. | time.                                                                        |
  237. ------------------------------------------------------------------------------*/
  238.   IThread ( );
  239.   IThread ( const IThread &aThread );
  240.   IThread ( const IThreadId &anID );
  241.   IThread ( const IReference<IThreadFn> &aFnObjRef,
  242.             Boolean          autoInitPM = IThread::defaultAutoInitPM() );
  243.   IThread ( OptlinkFnPtr     pfn,
  244.             void            *anArg,
  245.             Boolean          autoInitPM = IThread::defaultAutoInitPM() );
  246.   IThread ( SystemFnPtr      pfn,
  247.             unsigned long    anArg,
  248.             Boolean          autoInitPM = IThread::defaultAutoInitPM() );
  249.  
  250. virtual
  251.   ~IThread ( );
  252.  
  253. /*------------------------------ Starting/Stopping -----------------------------
  254. | These functions enable the starting and stopping of threads:                 |
  255. |   start   - Starts an asynchronous thread.  Threads can be started using     |
  256. |             any of the following means:                                      |
  257. |               o With an arbitrary IThreadFn.  The IThreadFn is passed in     |
  258. |                 using an IReference so that the IThreadFn can be deleted     |
  259. |                 (if necessary) when the thread terminates.                   |
  260. |               o With an OptlinkFnPtr function and void* argument.  This is   |
  261. |                 to provide support for functions otherwise startable using   |
  262. |                 _beginthread.                                                |
  263. |               o With a SystemFnPtr function and unsigned long argument.      |
  264. |                 This is to provide support for functions otherwise           |
  265. |                 startable using DosCreateThread.                             |
  266. |   stop    - Stops the thread.                                                |
  267. |   suspend - Suspends the thread's execution.                                 |
  268. |   resume  - Resumes the thread's execution.                                  |
  269. ------------------------------------------------------------------------------*/
  270. void
  271.   start   ( const IReference<IThreadFn> &aFnObjRef,
  272.             Boolean        autoInitPM = IThread::defaultAutoInitPM() ),
  273.   start   ( OptlinkFnPtr   pfn,
  274.             void          *anArg,
  275.             Boolean        autoInitPM = IThread::defaultAutoInitPM() ),
  276.   start   ( SystemFnPtr    pfn,
  277.             unsigned long  anArg,
  278.             Boolean        autoInitPM = IThread::defaultAutoInitPM() );
  279.  
  280. virtual void
  281.   stop    ( ),
  282.   suspend ( ),
  283.   resume  ( );
  284.  
  285. /*-------------------------------- Accessing -----------------------------------
  286. | These functions provide a means of getting and setting various thread        |
  287. | attributes:                                                                  |
  288. |   id          - Obtains the ID of the thread (0 indicates the thread is not  |
  289. |                 started).                                                    |
  290. |   current     - Returns a reference to a thread object that represents the   |
  291. |                 currently executing thread.                                  |
  292. |   currentId   - Returns the current thread ID.                               |
  293. |   asString    - Returns a string of the form "IThread(tid)".                 |
  294. |   asDebugInfo - Returns a representation of the thread as diagnostic         |
  295. |                 information.                                                 |
  296. ------------------------------------------------------------------------------*/
  297. static ICurrentThread
  298.  ¤t ( );
  299.  
  300. virtual IThreadId
  301.   id ( ) const;
  302.  
  303. static IThreadId
  304.   currentId ( );
  305.  
  306. virtual IString
  307.   asString    ( ) const,
  308.   asDebugInfo ( ) const;
  309.  
  310. /*----------------------------- Window Information List ------------------------
  311. | These functions provide access to the thread window information list.        |
  312. |   windowList    - Obtains a pointer to the window information list for this  |
  313. |                   thread.                                                    |
  314. |   setWindowList - Sets a pointer to the window information list for this     |
  315. |                   thread.                                                    |
  316. ------------------------------------------------------------------------------*/
  317. IWindowList
  318.  *windowList ( ) const;
  319.  
  320. IThread
  321.  &setWindowList ( IWindowList *list );
  322.  
  323. /*-------------------------------- Stack Size ----------------------------------
  324. | These functions provide access to the thread stack size:                     |
  325. |   stackSize           - Obtains the thread stack size (in bytes).            |
  326. |   setStackSize        - Sets the thread stack size (in bytes).  If the       |
  327. |                         thread is started, this value will take effect only  |
  328. |                         when the thread is stopped and restarted.            |
  329. |   defaultStackSize    - Obtains the default stack size (the value used by    |
  330. |                         default for new IThreads).                           |
  331. |   setDefaultStackSize - Sets the default stack size.                         |
  332. ------------------------------------------------------------------------------*/
  333. virtual unsigned long
  334.   stackSize ( ) const;
  335.  
  336. virtual IThread
  337.  &setStackSize ( unsigned long aSize );
  338.  
  339. static unsigned long
  340.   defaultStackSize ( );
  341.  
  342. static void
  343.   setDefaultStackSize ( unsigned long aSize );
  344.  
  345. /*----------------------- Presentation Manager Support -------------------------
  346. | These functions provide basic Presentation Manager (PM) support for          |
  347. | threads.  Additional Presenation Manager functions can be applied to the     |
  348. | current thread (see ICurrentThread):                                         |
  349. |   autoInitPM           - Obtains the setting of the flag that automatically  |
  350. |                          initializes Presentation Manager for this thread.   |
  351. |   setAutoInitPM        - Sets the flag that automatically initializes        |
  352. |                          Presentation Manager for this thread.               |
  353. |   defaultAutoInitPM    - Obtains the default flag that automatically         |
  354. |                          initializes Presentation Manager.  Unless this      |
  355. |                          flag is explicitly set using the                    |
  356. |                          setDefaultAutoInitPM function, this will return     |
  357. |                          true for programs running in a Presentation         |
  358. |                          Manager session and false for programs running in   |
  359. |                          a non-Presentation Manager session.                 |
  360. |   setDefaultAutoInitPM - Sets the default flag that automatically            |
  361. |                          initializes Presentation Manager.                   |
  362. |   stopProcessingMsgs   - Terminates the processing of window events          |                             |
  363. |                          (messages) initiated by the                         |
  364. |                          ICurrentThread::processMsgs member function.        |                 |
  365. ------------------------------------------------------------------------------*/
  366. virtual Boolean
  367.   autoInitPM ( ) const;
  368.  
  369. virtual IThread
  370.  &setAutoInitPM ( Boolean initFlag );
  371.  
  372. static Boolean
  373.   defaultAutoInitPM ( );
  374.  
  375. static void
  376.   setDefaultAutoInitPM ( Boolean initFlag );
  377.  
  378. virtual IThread
  379.  &stopProcessingMsgs ( );
  380.  
  381. /*---------------------------- Message Queue Size ------------------------------
  382. | These functions control the size of the Presentation Manager message queue:  |
  383. |   queueSize           - Obtains the Presentation Manager message queue size  |
  384. |                         to be used (or being used) for this thread.          |
  385. |   setQueueSize        - Sets the Presentation Manager message queue size     |
  386. |                         for this thread.                                     |
  387. |   defaultQueueSize    - Obtains the default Presentation Manager message     |
  388. |                         queue size to be used for new IThreads.              |
  389. |   setDefaultQueueSize - Sets the default Presentation Manager message queue  |
  390. |                         size.                                                |
  391. ------------------------------------------------------------------------------*/
  392. virtual long
  393.   queueSize ( ) const;
  394.  
  395. virtual IThread
  396.  &setQueueSize ( long queueSize );
  397.  
  398. static long
  399.   defaultQueueSize ( );
  400.  
  401. static void
  402.   setDefaultQueueSize ( long queueSize );
  403.  
  404. /*----------------------------- Thread Priority --------------------------------
  405. | These functions control the thread priority:                                 |
  406. |   priorityClass  - Obtains the priority class of the thread (a value of      |
  407. |                    type IApplication::PriorityClass).                        |
  408. |   setPriority    - Sets the priority class and level of the thread.          |
  409. |   priorityLevel  - Obtains the priority level of the thread (a value in the  |
  410. |                    range 0-31).                                              |
  411. |   adjustPriority - Changes the thread priority level by a given amount (a    |
  412. |                    value between -31 and 31).                                |
  413. ------------------------------------------------------------------------------*/
  414. virtual unsigned
  415.   priorityLevel ( ) const;
  416.  
  417. virtual IApplication::PriorityClass
  418.   priorityClass ( ) const;
  419.  
  420. virtual IThread
  421.  &setPriority    ( IApplication::PriorityClass aClass,
  422.                    unsigned                    level ),
  423.  &adjustPriority ( int delta );
  424.  
  425. /*--------------------------------- Testing ------------------------------------
  426. | This function tests various attributes of the thread:                        |
  427. |   isStarted - Returns true if the thread is currently active.                |
  428. ------------------------------------------------------------------------------*/
  429. virtual Boolean
  430.   isStarted ( ) const;
  431.  
  432. /*-------------------------------- Iteration -----------------------------------
  433. | The following provide utilities for iterating over the active threads for    |
  434. | the current application:                                                     |
  435. |   Cursor - Nested cursor class used to iterate over the set of active        |
  436. |            threads.  Note that this class will only provide access to        |
  437. |            threads "known" by IThread.                                       |
  438. ------------------------------------------------------------------------------*/
  439. class Cursor : public IVBase {
  440. typedef IVBase
  441.   Inherited;
  442. public:
  443. /*------------------------------- Constructor ----------------------------------
  444. | The constructor accepts an optional flag indicating whether all threads      |
  445. | should be enumerated or only those which have ICLUI windows.  The default    |
  446. | is all threads.                                                              |
  447. ------------------------------------------------------------------------------*/
  448.   Cursor ( Boolean allThreads = true );
  449.   ~Cursor ( );
  450.  
  451. /*----------------------------- Cursor Functions -------------------------------
  452. | These functions provide the basic cursor functionality of this class:        |
  453. |   setToFirst - Initializes the cursor to the first thread.                   |
  454. |   setToNext  - Advances cursor to the next thread.                           |
  455. |   isValid    - Returns true if the cursor is valid.                          |
  456. |   invalidate - Invalidates the cursor.                                       |
  457. |   threadId   - Returns the Id of the thread at the current cursor position.  |
  458. ------------------------------------------------------------------------------*/
  459. Boolean
  460.   setToFirst ( ),
  461.   setToNext  ( ),
  462.   isValid    ( ) const;
  463.  
  464. void
  465.   invalidate ( );
  466.  
  467. IThreadId
  468.   threadId   ( ) const;
  469.  
  470. private: /*------------------------ PRIVATE ----------------------------------*/
  471. Boolean
  472.   all,
  473.   advance ( );
  474. unsigned
  475.   cursor,
  476.   created;
  477. friend class IStartedThread;
  478. static unsigned
  479.   timeStamp;
  480. }; // class IThread::Cursor
  481.  
  482. protected:
  483. /*------------------------------ Implementation --------------------------------
  484. | These functions provide utilities used to implement this class:              |
  485. |   startedThread    - Returns the address of the corresponding                |
  486. |                      IStartedThread.                                         |
  487. |   newStartedThread - Returns a pointer to the new IStartedThread.            |
  488. ------------------------------------------------------------------------------*/
  489. virtual IStartedThread
  490.  *startedThread ( ) const;
  491.  
  492. static IStartedThread
  493.  *newStartedThread ( );
  494.  
  495. /*-------------------------------- Assignment ----------------------------------
  496. | This operator is used for assignment:                                        |
  497. |   operator = - Provides for assignment of one IThread to another             |
  498. |                (preserving resource allocation).                             |
  499. ------------------------------------------------------------------------------*/
  500. IThread
  501.  &operator = ( const IThread &aThread );
  502.  
  503. private: /*------------------------ PRIVATE ----------------------------------*/
  504. friend class ICurrentThread;
  505. friend class IWindow;
  506. IStartedThread
  507.  *prepareToStart ( const IReference<IThreadFn> &, Boolean );
  508. void
  509.   threadStarted ( IStartedThread *, int );
  510. IString
  511.   variable( const IString &key ) const;
  512. IThread
  513.  &setVariable( const IString &key,
  514.                const IString &value );
  515. static Boolean
  516.   inPMSession ( );
  517. Boolean
  518.   inMsgLoop ( ) const;
  519. IStartedThread
  520.  *thread;
  521. static unsigned long
  522.   dfltStackSize;
  523. static Boolean
  524.   dfltAutoInitPM;
  525. static long
  526.   dfltQueueSize;
  527. static ICurrentThread
  528.  *pCurrent;
  529. }; // IThread
  530.  
  531. class ICurrentThread : public IThread {
  532. typedef IThread
  533.   Inherited;
  534. /*******************************************************************************
  535. * The ICurrentThread class provides additional functions that can only be      *
  536. * applied to the current thread of execution.                                  *
  537. *                                                                              *
  538. * A reference to the sole instance of this class is obtained only by using     *
  539. * the static IThread::current member function.                                 *
  540. *                                                                              *
  541. * The resulting object is used to call the thread APIs that can only be        *
  542. * applied to the current thread of execution.  Essentially, these are the      *
  543. * APIs that operate on a per-thread basis but do not accept a thread ID as     *
  544. * an argument.                                                                 *
  545. *******************************************************************************/
  546. public:
  547. /*------------------Presentation Manager Support -------------------------------
  548. | These functions provide support for performing windowing (Presentation       |
  549. | Manager) activities on the current thread:                                   |
  550. |                                                                              |
  551. |   initializePM    - Sets up the Presentation Manager environment (anchor     |
  552. |                     block and message queue).                                |
  553. |   processMsgs     - Gets and dispatches Presentation Manager messages until  |
  554. |                     WM_QUIT is received.                                     |
  555. |   terminatePM     - Shuts down the Presentation Manager environment.         |
  556. |   isPMInitialized - Returns true if the Presentation Manager environment is  |
  557. |                     active for this thread.                                  |
  558. |   anchorBlock     - Obtains the anchor block handle for the thread (0 if not |
  559. |                     initialized).                                            |
  560. |   messageQueue    - Obtains the message queue handle for the thread (0 if    |
  561. |                     not initialized).                                        |
  562. ------------------------------------------------------------------------------*/
  563. virtual void
  564.   initializePM ( long queueSize = 0 ),
  565.   processMsgs  ( ),
  566.   terminatePM  ( );
  567.  
  568. virtual Boolean
  569.   isPMInitialized ( ) const;
  570.  
  571. virtual IAnchorBlockHandle
  572.   anchorBlock ( ) const;
  573.  
  574. virtual IMessageQueueHandle
  575.   messageQueue ( ),
  576.   messageQueue ( ) const;
  577.  
  578. /*-------------------------- Current Thread Function ---------------------------
  579. | These functions enable thread operations only applicable to the current      |
  580. | thread:                                                                      |
  581. |   remainingStack       - Returns an approximation of the number of stack     |
  582. |                          bytes remaining (0 if no started).                  |
  583. |   sleep                - Suspends the thread for a given number of           |
  584. |                          milliseconds.                                       |
  585. |   waitFor              - Causes the current thread to wait for a given       |
  586. |                          thread to terminate.                                |
  587. |   waitForAnyThread     - Causes the current thread to wait for any thread    |
  588. |                          to terminate (and returns its ID).                  |
  589. |   waitForAllThreads    - Causes the current thread to wait for all           |
  590. |                          secondary threads to terminate.                     |
  591. |   exit                 - Terminates the current thread with a given return   |
  592. |                          value.                                              |
  593. ------------------------------------------------------------------------------*/
  594. virtual unsigned long
  595.   remainingStack ( ) const;
  596.  
  597. virtual ICurrentThread
  598.  &sleep             ( unsigned long msecs ),
  599.  &waitFor           ( const IThread &anotherThread ),
  600.  &waitForAllThreads ( );
  601.  
  602. virtual IThreadId
  603.   waitForAnyThread ( );
  604.  
  605. virtual void
  606.   exit  ( unsigned long rc    );
  607.  
  608. /*--------------------------------- Overrides----------------------------------
  609. | This class reimplements these functions:                                     |
  610. |   id            - Returns the current thread's ID.                           |
  611. |   suspend       - Checks that the current thread is not a Presentation       |
  612. |                   Manager thread.                                            |
  613. |   startedThread - Returns a pointer to IStartedThread for the current thread.|
  614. ------------------------------------------------------------------------------*/
  615. virtual IThreadId
  616.   id ( ) const;
  617.  
  618. virtual void
  619.   suspend ( );
  620.  
  621. protected:
  622.  
  623. virtual IStartedThread
  624.  *startedThread ( ) const;
  625.  
  626. /*------------------------------- Constructor ----------------------------------
  627. | The constructor for this class is protected in order to prevent creation     |
  628. | of objects of this class except from within IThread::current.                |
  629. ------------------------------------------------------------------------------*/
  630.   ICurrentThread ( );
  631.  
  632. private: /*------------------------ PRIVATE ----------------------------------*/
  633. friend class IThread;
  634.   ~ICurrentThread ( );
  635. }; // ICurrentThread
  636.  
  637. /*----------------------------------------------------------------------------*/
  638. /* Resume compiler default packing and warning messages.                      */
  639. /*----------------------------------------------------------------------------*/
  640. #pragma pack()
  641. #pragma info(restore)
  642.  
  643.  
  644. #ifndef I_NO_INLINES
  645.   #include <ithread.inl>
  646. #endif
  647.  
  648. #endif /* _ITHREAD_ */
  649.