// Updates the dispatcher // @par: int current time (quantum) // @ret: int 1 for process put into real time queue // @ret: int 0 otherwise int updateDispatcher(int time) { // Create a pointer to the dispatcher so we don't modify dispatcher directly unless we need to Queue *queuePtr = dispatcher; // Create a new queue for elements that weren't able to be added Queue *newDispatcher = initializeQueue(); int rtQUpdated = 0; // Checks if dispatcher is empty if (!(queuePtr)) { printf("The queue is empty!\n\n"); return 0; } // Iterate through each element in the queue int i = 0; int count = numElems(queuePtr); // If the first process is NULL, we don't want to iterate through them // Double check that there are elements in queue if (queuePtr->process == NULL) { i = count; } // Keep an indicator to see if anything breaks int broken = 0; // Iterate through each element in the dispatcher while (i < count) { // Dequeue the next process from the queue PCB *currentProcess = dequeueProcess(&queuePtr)->process; // Queue is empty // Triple check if (currentProcess == NULL) { printf("BROKEN!\n"); broken = 1; break; } // If the process has "arrived", attempt to allocate resources to it if (time >= currentProcess->arrivalTime) { // Attempt to allocate resources to the process. int allocResult = allocateResources(currentProcess); if (allocResult) { // Resources were allocated successfully printf("* INITIALIZED pid: %d", currentProcess->pid); if (currentProcess->priority == 0) { rtQUpdated = 1; printf(", a real time process"); } printf("\n\n"); // Send the process to join the appropriate priority queue enqueueToPriority(currentProcess); } else { // Resources could not be allocated, move the process back on the dispatcher queue enqueueProcess(newDispatcher, currentProcess); } } else { // The time has not come for this process, add it to the new dispatcher enqueueProcess(newDispatcher, currentProcess); } i++; } // If the queue wasn't broken if (!broken) { if (dispatcher == NULL) { cleanQueue(dispatcher); } dispatcher = newDispatcher; } return rtQUpdated; }
int TParameterDeclaration::numComponents(RtInt vertices, RtInt corners, RtInt facets, RtInt faceVertices, RtInt faceCorners, RtInt colorComps) const { int n = numElems(vertices, corners, facets, faceVertices, faceCorners); return n*getComponents(colorComps);; }
bool empty() const {return (numElems() == 0); }
//////////////////////////////////////////////////////////////////////////////// // size - returns the bytes used for a parameter of this declaration // // Parameters: // vertices : Number of vertices (used by vertex class) // corners : Number of corners (used by varying class) // facets : Number of facets (used by uniform class) // facevertices : Number of vertices per face (used by facevertex class) // facecorners : Number of corners per face (used by facevarying class) // colorComps : Number of components per color // // Returns: // number of bytes // int TParameterDeclaration::size(RtInt vertices, RtInt corners, RtInt facets, RtInt faceVertices, RtInt faceCorners, RtInt colorComps) const { int n = numElems(vertices, corners, facets, faceVertices, faceCorners); if ( m_type == TYPE_COLOR ) n *= colorComps; return n*sizeOfType(m_type); }