home *** CD-ROM | disk | FTP | other *** search
/ Informática Multimedia: Special Games / INFESPGAMES.mdf / os2 / ribble / support / cthread.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-04  |  1.2 KB  |  85 lines

  1. #define INCL_DOS
  2. #define INCL_DOSSEMAPHORES
  3. #include <os2.h>
  4. #include <process.h>
  5.  
  6. #include <cthread.h>
  7.  
  8. CThread::CThread(void)
  9. {
  10.   hab = 0;
  11.   hmq = 0;
  12.   threadID = -1;
  13. }
  14.  
  15. CThread::~CThread()
  16. {
  17.   if (hmq)
  18.     {
  19.       WinDestroyMsgQueue(hmq);
  20.       hmq = 0;
  21.     }
  22.  
  23.   if (hab)
  24.     {
  25.       WinTerminate(hab);
  26.       hab = 0;
  27.     }
  28.  
  29.   Kill();
  30. }
  31.  
  32. void
  33. CThread::Run(void)
  34. {
  35.   if (threadID == -1)
  36.     {
  37. #if defined(__BORLANDC__)
  38.       threadID = _beginthread(CThreadMain, 64 * 1024, (PVOID)this);
  39. #else
  40.       threadID = _beginthread(CThreadMain, 0, 64 * 1024, (PVOID)this);
  41. #endif
  42.     }
  43. }
  44.  
  45. TID
  46. CThread::QueryTID(void)
  47. {
  48.   return (TID)threadID;
  49. }
  50.  
  51. void
  52. #if defined(__BORLANDC__) || defined(__WATCOMC__)
  53. #else
  54. _Optlink
  55. #endif
  56. CThreadMain(PVOID arg)
  57. {
  58.   CThread* obj = (CThread*)arg;
  59.  
  60.   obj->hab = WinInitialize(0);
  61.   obj->hmq = WinCreateMsgQueue(obj->hab, 0);
  62.   obj->ThreadProc();
  63. }
  64.  
  65. void
  66. CThread::Wait(void)
  67. {
  68.   if (threadID != -1)
  69.     {
  70.       DosWaitThread((PTID)&threadID, DCWW_WAIT);
  71.     }
  72. }
  73.  
  74. void
  75. CThread::Kill(void)
  76. {
  77.   if (threadID != -1)
  78.     {
  79.       DosKillThread((TID)threadID);
  80.       Wait();
  81.       threadID = -1;
  82.     }
  83. }
  84.  
  85.