home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / CLASS.ZIP / PROCESS.CC < prev    next >
Text File  |  1993-02-16  |  3KB  |  122 lines

  1. #include "process.h"
  2. #ifdef INCLUDESOURCE
  3. #include "tree.cc"
  4. #endif
  5.  
  6.  
  7. threadTree::threadTree(process *pProcessNew):tree((tree*)0)
  8. {      PIB *pPIB;
  9.  
  10. #ifdef SHOWCALLS
  11.        fprintf(stderr, "Calling threadTree(%x)!\n", this);
  12. #endif
  13.        DosGetInfoBlocks(&pTIB, &pPIB);
  14.        pProcess = pProcessNew;
  15. }
  16.  
  17.  
  18. typedef struct helpStruct
  19. {      HEV hev;
  20.        threadTree *pThreadTree;
  21. };
  22.  
  23.  
  24. void helpFct(struct helpStruct *pHelp)
  25. {      PIB *pPIB;
  26.        threadTree *pThreadTree = pHelp->pThreadTree;
  27.  
  28.        DosGetInfoBlocks(&pThreadTree->pTIB, &pPIB);
  29.        DosPostEventSem(pHelp->hev);
  30.        pThreadTree->run();
  31.        delete pThreadTree;
  32. }
  33.  
  34.  
  35. threadTree::threadTree(threadTree *pParentNew):tree(pParentNew)
  36. {      struct helpStruct help;
  37.        TID tid;
  38. #ifdef SHOWCALLS
  39.        fprintf(stderr, "Calling threadTree(%x)!\n", this);
  40. #endif
  41.        help.pThreadTree = this;
  42.        DosCreateEventSem((unsigned char*)0, &help.hev, (unsigned long)0, (BOOL32)0);
  43.        pProcess = pParentNew->pProcess;
  44.        DosCreateThread(&tid, helpFct, (unsigned long)&help, (unsigned long)0, 
  45.            (unsigned long)1024*1024);
  46.        DosWaitEventSem(help.hev, (unsigned int)SEM_INDEFINITE_WAIT);
  47.        DosCloseEventSem(help.hev);
  48. }
  49.  
  50.  
  51. threadTree::~threadTree(void)
  52. {      PIB *pPIBHelp;
  53.        TIB *pTIBHelp;
  54.  
  55. #ifdef SHOWCALLS
  56.        fprintf(stderr, "Calling ~threadTree(%x)!\n", this);
  57. #endif SHOWCALLS
  58.        DosGetInfoBlocks(&pTIBHelp, &pPIBHelp);
  59.        if (pTIBHelp != pTIB)
  60.        {
  61.                DosKillThread(pTIB->tib_ptib2->tib2_ultid);
  62.        }
  63. }
  64.  
  65.  
  66. process::process(int argcNew, char **argvNew):object()
  67. {      TIB *pTIB;
  68. #ifdef SHOWCALLS
  69.        fprintf(stderr, "Calling process(%x)!\n", this);
  70. #endif SHOWCALLS
  71.        DosGetInfoBlocks(&pTIB, &pPIB);
  72.        argc = argcNew;
  73.        argv = argvNew;
  74. }
  75.  
  76.  
  77. Boolean process::create(void)
  78. {
  79. #ifdef SHOWCALLS
  80.        fprintf(stderr, "Calling process::create(%x)!\n", this);
  81. #endif
  82.        if (!(pThreadTree = new threadTree(this)))
  83.                return FALSE;
  84.        else
  85.        {
  86. #ifdef DEBUG
  87.        fprintf(stderr, "pThreadTree->doSomething() = %x\n", &this->doSomething);
  88. #endif
  89.                return TRUE;
  90.        }
  91. }
  92.  
  93.  
  94. void process::destruct(void)
  95. {
  96. #ifdef SHOWCALLS
  97.        fprintf(stderr, "Calling process::destruct(%x)\n", this);
  98. #endif SHOWCALLS
  99.        delete pThreadTree;
  100.        pThreadTree = (threadTree*)0;
  101. }
  102.  
  103.  
  104. void process::doSomething(void)
  105. {
  106. #ifdef SHOWCALLS
  107.        fprintf(stderr, "Calling process::doSomething(%x)\n", this);
  108. #endif SHOWCALLS
  109. #ifdef DEBUG
  110.        fprintf(stderr, "pThreadTree->doSomething() = %x\n", &this->doSomething);
  111. #endif
  112.        pThreadTree->run();
  113. }
  114.  
  115.  
  116. process::~process(void)
  117. {
  118. #ifdef SHOWCALLS
  119.        fprintf(stderr, "Calling ~process(%x)\n", this);
  120. #endif
  121. }
  122.