home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spiele Shareware / os2games.iso / os2games / addons / gi / c / pmtools / pmthread.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-21  |  2.9 KB  |  96 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*   Main-Module   : none                                                   */
  4. /*                                                                          */
  5. /*   Version       : V1.00                                                  */
  6. /*                                                                          */
  7. /*   Date          : 15.10.92                                               */
  8. /*                                                                          */
  9. /*   Written       : MH                                                     */
  10. /*                                                                          */
  11. /*   Dependency    :                                                        */
  12. /*                                                                            */
  13. /*     Revision History :
  14.  
  15.     15.10.92    MH    Entfernen von PM-Threads
  16.     15.04.93    MH  Portierung auf 32 Bit
  17.                                                                             */
  18. /*--------------------------------------------------------------------------*/
  19. #define INCL_DOSPROCESS
  20. #include <pmthread.hpp>
  21. #include <stdlib.h>
  22.  
  23. //---------------- Methods for class thread ----------------------------------
  24. extern THREAD    *newthread;
  25.  
  26. //---------------- Methods for class pmthread --------------------------------
  27. void PMThreadStarter (void);
  28.  
  29. void APIENTRY PMThreadStarter (ULONG b)
  30.     {
  31.     PMTHREAD *found = (PMTHREAD *)b;
  32.  
  33.     found->hab = WinInitialize (0);
  34.     found->pmfunc ((ULONG)found->pmdata);
  35.     found->running = found->started = FALSE;
  36.     WinTerminate (found->hab);
  37.     found->hab = 0;
  38.     }
  39.  
  40. //---------------- Methods for class pmwinthread -----------------------------
  41. void PMWINTHREAD::Loop    (void)
  42.     {
  43.     started = running = TRUE;
  44.     error = OK;
  45.  
  46.     if (!Init (hab, hmq))               // Initialization fucked up
  47.         {
  48.         error = EUSERINIT;
  49.         return;
  50.         }
  51.  
  52.     while(TRUE)
  53.         {
  54.         while(WinGetMsg(hab, (QMSG *) &qmsg, NULL, 0, 0))
  55.             {
  56.             if (Control (hab, hmq, (QMSG *) &qmsg))
  57.                 WinDispatchMsg(hab, (QMSG *) &qmsg);
  58.             }
  59.  
  60.         if (!End (hab, hmq))
  61.             WinCancelShutdown(hmq, FALSE);
  62.         else
  63.             break;
  64.         }
  65.  
  66.     ShutDown (hab, hmq);
  67.     started = running = FALSE;
  68.     return;
  69.     }
  70.  
  71. unsigned PMTHREAD::Start (THREADFUNC func, void *newdata)
  72.     {
  73.     if (func)
  74.         pmfunc = func;
  75.     if (newdata)
  76.         pmdata = newdata;
  77.     return (THREAD::Start ());
  78.     }
  79. PMTHREAD::PMTHREAD    (THREADFUNC func, BOOL start) : THREAD(this, PMThreadStarter, FALSE)
  80.     {
  81.     pmfunc = func;
  82.     pmdata = NULL;
  83.     hab = 0;
  84.     if (start)
  85.         Start ();
  86.     };
  87. PMTHREAD::PMTHREAD    (void *newdata, THREADFUNC func, BOOL start) : THREAD(this, PMThreadStarter, FALSE)
  88.     {
  89.     pmfunc = func;
  90.     pmdata = newdata;
  91.     hab = 0;
  92.     if (start)
  93.         Start ();
  94.     };
  95. //============================================================================
  96.