00001 00002 00003 #ifndef __process_h__ 00004 #define __process_h__ 00005 00006 #include "common.h" 00007 #include "id.h" 00008 #include "program.h" 00009 #include "thread.h" 00010 00011 00012 00014 /* 00015 * a process is a collection of one or more threads 00016 */ 00017 class process 00018 : protected std::vector<thread*> 00019 { 00020 friend class virtualMachine; 00021 friend class std::vector<thread*>; 00022 00023 public: 00024 typedef void(*instructionPtr)(virtualMachine&, process&, thread&); 00025 typedef std::vector<instructionPtr> instructionSet; 00026 00028 /* 00029 * creates a thread at address 0 of the program 00030 */ 00031 process(program& prog, uInt pid); 00032 ~process(); 00033 00035 void clean(); 00036 00038 program& getProgram(); 00039 00041 processId getId(); 00042 00044 threadId spawnThread(address addr); 00045 00047 void killThread(threadId tid); 00048 00050 uInt getNumThreads(); 00051 00054 00057 address getThreadAddress(threadId tid); 00058 00060 /* 00061 * a thread is considered terminated if it 00062 * has no threads or has no program or the 00063 * program size is 0 00064 */ 00065 virtual bool isTerminated(); 00066 00067 protected: 00069 process(); 00070 00072 program* m_pProgram; 00073 00075 uInt m_threadCnt; 00076 00078 processId m_id; 00079 00080 private: 00081 }; 00082 00083 00084 00085 00086 00087 #endif 00088 00089