home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
CLASS.ZIP
/
PROCESS.CC
< prev
next >
Wrap
Text File
|
1993-02-16
|
3KB
|
122 lines
#include "process.h"
#ifdef INCLUDESOURCE
#include "tree.cc"
#endif
threadTree::threadTree(process *pProcessNew):tree((tree*)0)
{ PIB *pPIB;
#ifdef SHOWCALLS
fprintf(stderr, "Calling threadTree(%x)!\n", this);
#endif
DosGetInfoBlocks(&pTIB, &pPIB);
pProcess = pProcessNew;
}
typedef struct helpStruct
{ HEV hev;
threadTree *pThreadTree;
};
void helpFct(struct helpStruct *pHelp)
{ PIB *pPIB;
threadTree *pThreadTree = pHelp->pThreadTree;
DosGetInfoBlocks(&pThreadTree->pTIB, &pPIB);
DosPostEventSem(pHelp->hev);
pThreadTree->run();
delete pThreadTree;
}
threadTree::threadTree(threadTree *pParentNew):tree(pParentNew)
{ struct helpStruct help;
TID tid;
#ifdef SHOWCALLS
fprintf(stderr, "Calling threadTree(%x)!\n", this);
#endif
help.pThreadTree = this;
DosCreateEventSem((unsigned char*)0, &help.hev, (unsigned long)0, (BOOL32)0);
pProcess = pParentNew->pProcess;
DosCreateThread(&tid, helpFct, (unsigned long)&help, (unsigned long)0,
(unsigned long)1024*1024);
DosWaitEventSem(help.hev, (unsigned int)SEM_INDEFINITE_WAIT);
DosCloseEventSem(help.hev);
}
threadTree::~threadTree(void)
{ PIB *pPIBHelp;
TIB *pTIBHelp;
#ifdef SHOWCALLS
fprintf(stderr, "Calling ~threadTree(%x)!\n", this);
#endif SHOWCALLS
DosGetInfoBlocks(&pTIBHelp, &pPIBHelp);
if (pTIBHelp != pTIB)
{
DosKillThread(pTIB->tib_ptib2->tib2_ultid);
}
}
process::process(int argcNew, char **argvNew):object()
{ TIB *pTIB;
#ifdef SHOWCALLS
fprintf(stderr, "Calling process(%x)!\n", this);
#endif SHOWCALLS
DosGetInfoBlocks(&pTIB, &pPIB);
argc = argcNew;
argv = argvNew;
}
Boolean process::create(void)
{
#ifdef SHOWCALLS
fprintf(stderr, "Calling process::create(%x)!\n", this);
#endif
if (!(pThreadTree = new threadTree(this)))
return FALSE;
else
{
#ifdef DEBUG
fprintf(stderr, "pThreadTree->doSomething() = %x\n", &this->doSomething);
#endif
return TRUE;
}
}
void process::destruct(void)
{
#ifdef SHOWCALLS
fprintf(stderr, "Calling process::destruct(%x)\n", this);
#endif SHOWCALLS
delete pThreadTree;
pThreadTree = (threadTree*)0;
}
void process::doSomething(void)
{
#ifdef SHOWCALLS
fprintf(stderr, "Calling process::doSomething(%x)\n", this);
#endif SHOWCALLS
#ifdef DEBUG
fprintf(stderr, "pThreadTree->doSomething() = %x\n", &this->doSomething);
#endif
pThreadTree->run();
}
process::~process(void)
{
#ifdef SHOWCALLS
fprintf(stderr, "Calling ~process(%x)\n", this);
#endif
}