bool LLObjectMediaDataClient::processQueueTimer() { if(isEmpty()) return true; LL_DEBUGS("LLMediaDataClient") << "started, SORTED queue size is: " << mQueue.size() << ", RR queue size is: " << mRoundRobinQueue.size() << LL_ENDL; LL_DEBUGS("LLMediaDataClientQueue") << " SORTED queue is: " << mQueue << LL_ENDL; LL_DEBUGS("LLMediaDataClientQueue") << " RR queue is: " << mRoundRobinQueue << LL_ENDL; // purgeDeadRequests(); sortQueue(); LL_DEBUGS("LLMediaDataClientQueue") << "after sort, SORTED queue is: " << mQueue << LL_ENDL; serviceQueue(); swapCurrentQueue(); LL_DEBUGS("LLMediaDataClient") << "finished, SORTED queue size is: " << mQueue.size() << ", RR queue size is: " << mRoundRobinQueue.size() << LL_ENDL; LL_DEBUGS("LLMediaDataClientQueue") << " SORTED queue is: " << mQueue << LL_ENDL; LL_DEBUGS("LLMediaDataClientQueue") << " RR queue is: " << mRoundRobinQueue << LL_ENDL; return isEmpty(); }
void Renderable::show() { lockQueue(_queueVisible); addToQueue(_queueVisible); sortQueue(_queueVisible); unlockQueue(_queueVisible); }
int main(){ int i,j,time, timeQuantum; process list[NUM]; processQueue queue; int totalWaitTime=0; int totalBurstTime=0; int timeProcessed=0; printf("***Round Robin - preemptive scheduling***\n"); printf("Enter time quantum: "); scanf("%d", &timeQuantum); for(i=0; i<NUM; i++){ printf("Enter Process %d Burst time: ", i); scanf("%d", &list[i].burstTime); printf("Enter Process %d Arrival time: ", i); scanf("%d", &list[i].arrivalTime); list[i].name=(char)(i+48); list[i].waitTime=0; totalBurstTime+=list[i].burstTime; } sortListByAT(list); initQueue(&queue); for(time=0; time<totalBurstTime; time++) { timeProcessed++; printf("CPU Cycle %d\n",time); checkProcessQueue(&queue,list,time); if(queue.size!=0) run(&queue.list[queue.front]);//run current process else printf("CPU Idle\n"); for(i=queue.front+1; i<=queue.rear; i++){ //all the rest of processes wait wait(&queue.list[i]); } if(queue.list[queue.front].burstTime==0){ totalWaitTime += queue.list[queue.front].waitTime; deQueue(&queue); timeProcessed=0; } else if(time != 0 && ((timeProcessed) % timeQuantum)==0){ sortQueue(&queue); timeProcessed=0; } } printf("\nAverage wait time - %f\n", (float)(totalWaitTime)/NUM); return 0; }
void *schedulerFunction(void *pointer) { while (remainingFlows != 0) { //printf("SCHEDULER: Trying to gain control of remainingFlowsMutex!\n"); pthread_mutex_lock(&remainingFlowsMutex); //printf("SCHEDULER: Got control of remainingFlowsMutex!\n"); //printf("SCHEDULER: Waiting for flows to finish transmitting!\n"); // Waits to be signaled that another flow can transmit. pthread_cond_wait(&nobodyTransmittingCondVar, &remainingFlowsMutex); //printf("SCHEDULER: Flow finished transmitting!\n"); pthread_mutex_unlock(&remainingFlowsMutex); // While the queue of flows waiting to transmit is empty: Do nothing while(flowQueue[0]->flowNumber == 0); pthread_mutex_lock(&flowQueueMutex); // Sort the queue of flows waiting to transmit (mutex’d). sortQueue(flowQueue); // Remove the head of the queue and signal flow to transmit flowPointer flowToTransmit = flowQueue[0]; flow emptyFlow; emptyFlow.flowNumber = 0; flowQueue[0] = &emptyFlow; // Move the rest of the queue down one spot int i; for (i = 1; i < numberOfFlows; i ++) { flowQueue[i - 1] = flowQueue[i]; } currentlyTransmittingFlow = flowToTransmit; //pthread_mutex_unlock(&flowQueueMutex); //pthread_mutex_lock(&remainingFlowsMutex); remainingFlows --; //printf("SCHEDULER: Signalling flow %d to begin!\n", currentlyTransmittingFlow->flowNumber); pthread_cond_broadcast(&somebodyTransmittingCondVar); pthread_mutex_unlock(&flowQueueMutex); } return (void *) 0; }
void PolyQueue::flush(TextureCache* io_pTextureCache, IDirect3DDevice2* io_pD3DDevice2) { // First, sort the queue... sortQueue(); // and emit all sorted polys for (int i = 0; i < m_numQueuedPolys; i++) { if (m_pQueue[i].primType == PolyPrim) { emitQueuedPoly(io_pTextureCache, io_pD3DDevice2, &m_pQueue[i]); } else if (m_pQueue[i].primType == LinePrim) { emitQueuedLine(io_pD3DDevice2, &m_pQueue[i]); } else { emitQueuedPoint(io_pD3DDevice2, &m_pQueue[i]); } } m_numQueuedPolys = 0; }
bool LLMediaDataClient::processQueueTimer() { sortQueue(); if(!isEmpty()) { LL_DEBUGS("LLMediaDataClient") << "QueueTimer::tick() started, SORTED queue size is: " << mSortedQueue.size() << ", RR queue size is: " << mRoundRobinQueue.size() << LL_ENDL; LL_DEBUGS("LLMediaDataClientQueue") << "QueueTimer::tick() started, SORTED queue is: " << mSortedQueue << LL_ENDL; LL_DEBUGS("LLMediaDataClientQueue") << "QueueTimer::tick() started, RR queue is: " << mRoundRobinQueue << LL_ENDL; } serviceQueue(); LL_DEBUGS("LLMediaDataClient") << "QueueTimer::tick() finished, SORTED queue size is: " << mSortedQueue.size() << ", RR queue size is: " << mRoundRobinQueue.size() << LL_ENDL; LL_DEBUGS("LLMediaDataClientQueue") << "QueueTimer::tick() finished, SORTED queue is: " << mSortedQueue << LL_ENDL; LL_DEBUGS("LLMediaDataClientQueue") << "QueueTimer::tick() finished, RR queue is: " << mRoundRobinQueue << LL_ENDL; return isEmpty(); }
//********************************************************************************************************************* void linda::LindaCommunicator::wakeProcesses(linda::TupleFileUtils::tuple *tuple) { std::vector<linda::ProcessFileUtils::process> pids = linda::MatchesFinder::returnProcessQueue(proc_fd, tuple); sortQueue(pids); int input = 0; for (ProcessFileUtils::process pid : pids) { if(!input) { ProcessFileUtils::process ptr; ProcessFileUtils::readRecord(proc_fd, &ptr, pid.record_id); ptr.found = 1; ProcessFileUtils::writeRecord(proc_fd, &ptr, pid.record_id); ProcessFileUtils::unlockRecord(proc_fd, sizeof(ptr), ptr.record_id); int temp_fd = open((DEFAULT_FILEPATH + DEF_MES_FILE_PREF + std::to_string(pid.pid)).c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); TupleFileUtils::writeRecord(temp_fd, tuple, 0); if (close(temp_fd) == -1) { TupleFileUtils::unlockRecord(tuple_fd, sizeof(*tuple), tuple->record_id); throw linda::LindaException("LindaCommunicator::wakeProcesses close(temp_fd):"+ std::string(strerror(errno))); } ProcessFileUtils::wakeupProcess(pid.pid); if (ptr.flag) { TupleFileUtils::setRecordTaken(tuple_fd, tuple->record_id, 0); input = 1; } } else { ProcessFileUtils::unlockRecord(proc_fd, sizeof(pid), pid.record_id); } } TupleFileUtils::unlockRecord(tuple_fd, sizeof(*tuple), tuple->record_id); }
PUBLIC void *ExtModeMalloc(uint32_T size) { boolean_T keepTrying = false; MemBufHdr *LocalMemBuf; /* Requested buffer (NULL if none available). */ MemBufHdr *FreeMemBuf; /* First free buffer big enough for request. */ /* * Must allocate enough space for the requested number of bytes plus the * size of the memory buffer header. */ int sizeToAlloc = size + sizeof(MemBufHdr); while (!keepTrying) { keepTrying = true; LocalMemBuf = NULL; FreeMemBuf = NULL; /* Initialize the free queue. */ if (FreeQueue == NULL) initFreeQueue(); /* Find first free packet big enough for our request. */ FreeMemBuf = findFirstFreeMemBuf(sizeToAlloc); if (FreeMemBuf == NULL) { /* We couldn't find a free buffer. Run garbage collection to merge free buffers together and try again. */ sortQueue(FreeQueue); FreeMemBuf = findFirstFreeMemBuf(sizeToAlloc); } /* No free buffers are available which satisfy the request. */ if (FreeMemBuf == NULL) goto EXIT_POINT; /* * Found a free buffer with enough space. Carve out the exact buffer size * needed from the end of the free buffer. */ LocalMemBuf = (MemBufHdr *)(FreeMemBuf->MemBuf + FreeMemBuf->size - sizeToAlloc); /* * The pointer to the free memory must be longword aligned. If it * is not, adjust the size to allocate and try again. */ { int alignBytes = (int)LocalMemBuf % 4; if (alignBytes) { sizeToAlloc += (4-alignBytes); keepTrying = false; } } } /* Set up the new packet's info. */ LocalMemBuf->memBufPrev = NULL; LocalMemBuf->memBufNext = NULL; LocalMemBuf->MemBuf = (char *)LocalMemBuf + sizeof(MemBufHdr); LocalMemBuf->size = size; /* Insert the newly created buffer into the InUseQueue. */ inUseQueueInsert(LocalMemBuf); /* Update the free packet's size to reflect giving up a piece. */ FreeMemBuf->size -= sizeToAlloc; EXIT_POINT: if (LocalMemBuf) { #ifdef VERBOSE numBytesAllocated += sizeToAlloc; printf("\nBytes allocated: %d out of %d.\n", numBytesAllocated, EXTMODE_STATIC_SIZE); #endif return LocalMemBuf->MemBuf; } #ifdef VERBOSE printf("\nBytes allocated: %d out of %d.", numBytesAllocated+sizeToAlloc, EXTMODE_STATIC_SIZE); printf("\nMust increase size of static allocation!\n"); #endif return NULL; }
void Renderable::resort() { sortQueue(_queueVisible); }