Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

virtualMachine.h

Go to the documentation of this file.
00001 00002 00003 #ifndef __virtualMachine_h__ 00004 #define __virtualMachine_h__ 00005 00006 00007 #include "common.h" 00008 #include "id.h" 00009 #include "process.h" 00010 00011 00012 00013 typedef void(*instructionPtr)(virtualMachine&, process&, thread&); 00014 typedef std::vector<instructionPtr> instructionSet; 00015 00016 00017 00019 class virtualMachine 00020 : protected instructionSet 00021 { 00022 public: 00023 virtualMachine() : m_usedCycles(1.0f) 00024 , m_idleCnt(0) 00025 , m_numProcesses(0) 00026 , m_activeProcesses(false) {} 00027 00028 ~virtualMachine(); 00029 00031 instruction addInstruction(instructionPtr instrPtr); 00032 00034 bool replaceInstruction(instruction instr, instructionPtr instrPtr); 00035 00037 uInt getNumInstructions() { return static_cast<uInt>(size()); } 00038 00040 processId run(program& prog); 00041 00043 void kill(processId pid); 00044 00046 process* getProcess(processId pid); 00047 00049 uInt getNumProcesses() { return m_numProcesses; } 00050 00052 /* 00053 * \note should be between 0 and 1 00054 */ 00055 void setNumUsedCycles(float num); 00056 00058 bool activeProcesses() { return m_activeProcesses; } 00059 00061 /* 00062 * executes one instruction for each process 00063 */ 00064 void step(); 00065 00067 void update(float deltaT); 00068 00069 protected: 00071 virtual bool canBeExecuted(process& proc); 00072 00074 /* 00075 * only called if canBeExecuted returns false so 00076 * the condition of canBeExecuted can be assumed 00077 */ 00078 virtual bool shouldBeTerminated(process& proc); 00079 00081 virtual void kill(process& proc); 00082 00084 std::vector<process*> m_pProcesses; 00085 00087 uInt m_numProcesses; 00088 00091 idGen<recycleReleasedIds, noWrapAround> m_processIdGen; 00092 00093 float m_usedCycles; 00094 uInt m_idleCnt; 00095 00098 bool m_activeProcesses; 00099 00100 private: 00101 }; 00102 00103 00104 00105 #endif 00106

Generated on Sun Mar 6 22:12:28 2005 for virtualMachine03 by doxygen 1.3.7