void ReliabilitySystem::update( float deltaTime ) { acked.clear(); advanceQueueTime( deltaTime ); updateQueues(); updateStats(); #ifdef NET_UNIT_TEST validate(); #endif }
char nfaExecTamarama0_QR(const struct NFA *n, struct mq *q, ReportID report) { DEBUG_PRINTF("exec rose\n"); struct mq q1; q1.cur = q1.end = 0; char rv = 0; const struct Tamarama *t = getImplNfa(n); while (q->cur < q->end) { updateQueues(t, q, &q1); } if (q1.cur < q1.end) { rv = nfaQueueExecRose(q1.nfa, &q1, report); } DEBUG_PRINTF("exec rose rv:%u\n", rv); return rv; }
void DetachThreadQueue::threadedFunction(){ lock(); int nPending = pending.size(); int nProcessing = processing.size(); unlock(); if(verbose) printf("DetachThreadQueue::threadedFunction() start processing\n"); #ifdef TARGET_OSX pthread_setname_np("DetachThreadQueue Manager"); #endif while( ( nPending > 0 || nProcessing > 0 ) && !timeToStop ){ bool needToRest = false; lock(); nPending = pending.size(); nProcessing = processing.size(); if ( nPending > 0 && nProcessing < maxProcessing ){ GenericWorkUnit * w = pending[0]; pending.erase( pending.begin() ); w->processInThread(); processing.push_back(w); }else{ needToRest = true; } unlock(); updateQueues(); if (needToRest) ofSleepMillis(restTime); } if(verbose) printf("DetachThreadQueue::threadedFunction() end processing %f\n", ofGetElapsedTimef() ); if (!timeToStop){ if (verbose) printf("detaching DetachThreadQueue thread!\n"); pthread_detach(pthread_self()); //fixing that nasty zombie ofThread bug here } }
char nfaExecTamarama0_Q2(const struct NFA *n, struct mq *q, s64a end) { DEBUG_PRINTF("exec to match\n"); struct mq q1; char rv = 0; char copy = 0; const struct Tamarama *t = getImplNfa(n); while (q->cur < q->end && q_cur_loc(q) <= end && rv != MO_MATCHES_PENDING) { updateQueues(t, q, &q1); rv = nfaQueueExec2_raw(q1.nfa, &q1, end); q->report_current = q1.report_current; copy = 1; } if (copy) { copyBack(t, q, &q1); } return rv; }
char nfaExecTamarama0_Q(const struct NFA *n, struct mq *q, s64a end) { DEBUG_PRINTF("exec\n"); struct mq q1; char rv = MO_ALIVE; char copy = 0; const struct Tamarama *t = getImplNfa(n); while (q->cur < q->end && q_cur_loc(q) <= end) { updateQueues(t, q, &q1); rv = nfaQueueExec_raw(q1.nfa, &q1, end); q->report_current = q1.report_current; copy = 1; if (can_stop_matching(q->scratch)) { break; } } if (copy) { copyBack(t, q, &q1); } return rv; }
int main(int argc, char *argv[]) { int waitingIndex; setUpProcesses(); totalProcesses = numberOfProcesses; //error management of invalid number of processes quantum = readInt(&argv[1]); if (checkErrors(quantum) == -1) { error("Invalid number of processes"); return -1; } //sort processes by arrival time and priority qsort(processes, numberOfProcesses, sizeof(process), compareByArrival); initializeProcessQueue(&readyQueue); initializeProcessQueue(&waitingQueue); setupCPUS(); //set the quantum slice if (checkErrors(quantum) == -2) { error_bad_quantum(); return -1; } while (1) { preparePreQueue(); // if finished cpu burst, move to waiting queue if it is not the last cpu burst int cpuIndex = 0; int cpuUse = 0; // set up the current CpuBursts cpuBurstAllocation(cpuIndex, cpuUse); //sort waiting queue by processes priority int waitingQueueSize = waitingQueue.size; // iterate over queue where there are no indexes, and are waiting for (waitingIndex = 0; waitingIndex < waitingQueueSize; waitingIndex++) { dequeueEnqueueWaitingBusts(waitingIndex, waitingQueueSize); } //sort preReadyQueue and queue the expired time slices to the ready queue qsort(preReadyQueue, preReadyQueueSize, sizeof(process*), comparePIDs); qsort(tempProcess, tempProcessSize, sizeof(process*), comparePIDs); int j; //previous processes with expired time slices go into ready queue first as is in fifo for (j = 0; j < tempProcessSize; j++) { enqueueProcess(&readyQueue, tempProcess[j]); } tempProcessSize = 0; //enqueue everything in the ready queue for (j = 0; j < preReadyQueueSize; j++) { enqueueProcess(&readyQueue, preReadyQueue[j]); } preReadyQueueSize = 0; //assign the available cpu to first process of ready queue for (cpuIndex = 0; cpuIndex < NUMBER_OF_PROCESSORS; cpuIndex++) { conditionalCPUProcessQueue(cpuIndex, preReadyQueueSize, tempProcessSize); } //update burst of all processes in every queue int r; for (r = 0; r < readyQueue.size; r++) { updateQueues(); } if (cpuUse == 0 && waitingQueue.size == 0 && (numberOfProcesses - nextProcess) == 0) { break; // exit loop if no cpu in use or no running processes and none in waiting queue } timer++; //increment one time unit for each loop } setUpPrintVariables(); //print values printf("Average waiting time : %.2f units\n", totalWaitingTime/(double)numberOfProcesses); printf("Average turnaround Time : %.2f units\n", totalTurnAroundTime/(double)numberOfProcesses); printf("Time all processes finished : %d\n", timer); printf("Average CPU utilization : %.1f%%\n", 100.0 * cpuUseTotal / timer); printf("Number of context switches : %d\n", context); printf("PID(s) of last process(es) to finish : %d\n", lastPID); return 0; }