home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / games / gi / c / tools / thread.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-20  |  3.1 KB  |  126 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.     18.10.92    RF    erbt ERROR
  17.     27.02.93    RF    Statt DosCreateThread wird _dosbeginthread gebraucht
  18.     15.04.93    MH  Portierung auf 32 Bit
  19.  
  20.                                                                             */
  21. /*--------------------------------------------------------------------------*/
  22. #define INCL_DOSPROCESS
  23. #include <thread.hpp>
  24. #include <stdlib.h>
  25. #include <process.h>
  26.  
  27.  
  28. //---------------- Methods for class thread ----------------------------------
  29.  
  30. THREAD::THREAD    ()
  31.     {
  32.     PTIB    ptib;
  33.     PPIB    ppib;
  34.  
  35.     DosGetInfoBlocks (&ptib, &ppib);
  36.     tid = ptib->tib_ordinal;
  37.     pid = ppib->pib_ulpid;
  38.  
  39.     threadfunc        = NULL;
  40.     started            = TRUE;
  41.     running            = TRUE;
  42.     stacksize        = DEF_STACKSIZE;
  43.     error            = OK;
  44.     }
  45.  
  46. THREAD::THREAD    (THREADFUNC func, BOOL start)
  47.     {
  48.     PTIB    ptib;
  49.     PPIB    ppib;
  50.  
  51.     DosGetInfoBlocks (&ptib, &ppib);
  52.     pid = ppib->pib_ulpid;
  53.  
  54.     threadfunc        = func;
  55.     started            = start;
  56.     running            = FALSE;
  57.     stacksize        = DEF_STACKSIZE;
  58.     error            = OK;
  59.     data            = NULL;
  60.     tid                = 0;
  61.  
  62.     if (start)
  63.         Start (func);
  64.     }
  65.  
  66. THREAD::THREAD    (void *newdata, THREADFUNC func, BOOL start)
  67.     {
  68.     PTIB    ptib;
  69.     PPIB    ppib;
  70.  
  71.     DosGetInfoBlocks (&ptib, &ppib);
  72.     pid = ppib->pib_ulpid;
  73.  
  74.     threadfunc        = func;
  75.     started            = FALSE;
  76.     running            = FALSE;
  77.     stacksize        = DEF_STACKSIZE;
  78.     error            = OK;
  79.     data            = newdata;
  80.     tid                = 0;
  81.  
  82.     if (start)
  83.         Start (func, data);
  84.     }
  85.  
  86. void THREAD::Suspend ()
  87.     {
  88.     if (!started || !running)
  89.         return;
  90.  
  91.     DosSuspendThread (tid);
  92.     running = FALSE;
  93.     }
  94.  
  95. void THREAD::Resume ()
  96.     {
  97.     if (running)
  98.         return;
  99.  
  100.     DosResumeThread (tid);
  101.     running = TRUE;
  102.     }
  103.  
  104. unsigned THREAD::Start (THREADFUNC func, void *newdata)
  105.     {
  106.     if (started)
  107.         return (error = OK);
  108.  
  109.     if (func)
  110.         threadfunc = func;
  111.     if (!threadfunc)
  112.         return (error = ENOFUNC);
  113.  
  114.     if (newdata)
  115.         data = newdata;
  116.  
  117.     if (DosCreateThread (&tid, threadfunc, (ULONG)data, 0, stacksize))
  118.         return (error = ESTARTTHREAD);
  119.  
  120.     started = TRUE;
  121.     running = TRUE;
  122.  
  123.     return (error = OK);
  124.     }
  125. //============================================================================
  126.