#include "bus.h" CBus::CBus(void): BusyCycles(0), ProcQueue(NULL), TotBusyCycles(0) {} CBus::CBus(int bsize): BusyCycles(0), ProcQueue(NULL), TotBusyCycles(0), BlockSize(bsize) {} int CBus::getBusyCycles(void) { return BusyCycles; } long int CBus::getTotBusyCycles(void) { return TotBusyCycles; } void CBus::decBusyCycles(void) { BusyCycles--; } void CBus::setBusyCycles(int busycycles) { BusyCycles=busycycles; TotBusyCycles+=BusyCycles; } struct PQ* CBus::getProcQueue(void) { return ProcQueue; } //************************************************************ //pops the next processor in the queue, returns the struct PQ int CBus::executeNextRequest(CMemory* cm) { int bindex=0; long int block=0; int nextProcNum = ProcQueue->PE; long int addressReq = ProcQueue->address; int Job = ProcQueue->job; //if there is only one in list if(ProcQueue->next==NULL) { free(ProcQueue); ProcQueue=NULL; } else { struct PQ* nextP = ProcQueue->next; free(ProcQueue); ProcQueue=nextP; } /* if(Job==BROADCAST) { setBusyCycles(BlockSize); long int writeaddr=addressReq; int writebindex=writeaddr%BlockSize; long int writeblock=((writeaddr-writebindex)/BlockSize); for(int k=0; kBlocks[writeblock].getC(k)>0 && k!=nextProcNum) { cm->Blocks[writeblock].setC(k, (cm->Blocks[writeblock].getC(k)-1)); if(cm->Blocks[writeblock].getC(k)==0) cm->Blocks[writeblock].decProcCount(); } } } else { //we need to find out if we need to retrieve from CM bindex=addressReq%BlockSize; block=(addressReq-bindex)/BlockSize; //we need to go to Central Memory if(cm->Blocks[block].getProcCount()<0) { setBusyCycles(1+3+BlockSize); } else { setBusyCycles(1+BlockSize); } cm->Blocks[block].setC(nextProcNum, C); } */ return nextProcNum; } //************************************************************ //************************************************************ //fcn adds a processor to the queue to use the bus void CBus::addProcToQueue(int procnum, long int address, int job) { struct PQ* tail=NULL; //if there is none in queue if(ProcQueue == NULL) { ProcQueue=(struct PQ*)malloc(sizeof(struct PQ)); // ProcQueue->next=ProcQueue; // ProcQueue->last=ProcQueue; ProcQueue->next=NULL; ProcQueue->PE=procnum; ProcQueue->address=address; ProcQueue->job=job; } //if there is a queue else { struct PQ* newProc=(struct PQ*)malloc(sizeof(struct PQ)); tail=ProcQueue; while(tail->next!=NULL) tail=tail->next; tail->next=newProc; tail=tail->next; tail->PE=procnum; tail->address=address; tail->job=job; tail->next=NULL; /* struct PQ* last = ProcQueue->last; ProcQueue->last=(struct PQ*)malloc(sizeof(struct PQ)); ProcQueue->last->next=ProcQueue; last->next=ProcQueue->last; ProcQueue->last->last=last; ProcQueue->last->PE=procnum; ProcQueue->last->address=address; ProcQueue->last->job=job; */ } } //************************************************************