void ScriptMachine::execute(float dt) { int ms = dt * 1000.f; for(auto t = _activeThreads.begin(); t != _activeThreads.end(); ++t ) { auto& thread = *t; executeThread( thread, ms ); if( thread.finished ) { t = _activeThreads.erase( t ); } } }
int main(int argc, char **argv) { checkArgc(argc); studentsWaiting = inputValidation(argv[1]); officeLimit = inputValidation(argv[2]); pthread_mutex_init(&office_mutex, NULL); pthread_mutex_init(&student_mutex, NULL); pthread_mutex_init(&professor_mutex, NULL); pthread_mutex_init(&student_question_mutex, NULL); pthread_cond_init(&professor_complete_cv, NULL); pthread_cond_init(&student_question_cv, NULL); pthread_cond_init(&office_capacity_cv, NULL); executeThread(studentsWaiting); return 0; }
/*! * \brief IPProcessGrid::execute */ void IPProcessGrid::execute(bool forcedUpdate /* = false*/) { // if no processes yet, then exit if(_scene->steps()->size() < 1) { return; } // if already running or nothing has changed, exit if(_isRunning || !_updateNeeded) { return; } // prevent user changes during execution _mainWindow->lockScene(); _isRunning = true; _sequenceCount = 0; buildQueue(); int totalDurationMs = 0; // execute the processes int counter = 0; int limit = 10000; QList<IPProcessStep*> afterProcessingList; QListIterator<IPProcessStep *> it(_processList); while (it.hasNext() && counter < limit) { if(_stopExecution) return; IPProcessStep* step = it.next(); _currentStep = step; // make sure the progress bar gets filled updateProgress(1); // source processes don't have inputs if(step->process()->isSource()) { // check if is sequence //IPLLoadImageSequence* sequenceProcess = dynamic_cast<IPLLoadImageSequence*>(step->process()); // update if index has changed /*if(sequenceProcess && (_sequenceIndex != _lastSequenceIndex)) { sequenceProcess->setSequenceIndex(_sequenceIndex); propagateNeedsUpdate(sequenceProcess); }*/ // execute thread if(!step->process()->isResultReady() || forcedUpdate) { step->process()->resetMessages(); step->process()->beforeProcessing(); int durationMs = executeThread(step->process()); //step->process()->afterProcessing(); // afterProcessing will be called later afterProcessingList.append(step); totalDurationMs += durationMs; step->setDuration(durationMs); if(!step->process()->hasErrors()) step->updateThumbnail(); // update error messages _mainWindow->updateProcessMessages(); } /*if(sequenceProcess) { int currentSequenceCount = sequenceProcess->sequenceCount(); _sequenceCount = std::max(_sequenceCount, currentSequenceCount); emit sequenceChanged(_sequenceIndex, _sequenceCount); }*/ } else { if(!step->process()->isResultReady() || forcedUpdate) { // execute process once for every input for(int i=0; i < step->edgesIn()->size(); i++) { IPProcessEdge* edge = step->edgesIn()->at(i); int indexFrom = edge->indexFrom(); int indexTo = edge->indexTo(); IPProcessStep* stepFrom = edge->from(); IPLImage* result = static_cast<IPLImage*>(stepFrom->process()->getResultData(indexFrom)); // invalid result, stopp the execution if(!result) { QString msg("Invalid operation at step: "); msg.append(QString::fromStdString(stepFrom->process()->title())); _mainWindow->showMessage(msg, MainWindow::MESSAGE_ERROR); break; } // execute thread step->process()->resetMessages(); step->process()->beforeProcessing(); int durationMs = executeThread(step->process(), result, indexTo, mainWindow()->useOpenCV()); //step->process()->afterProcessing(); // afterProcessing will be called later afterProcessingList.append(step); totalDurationMs += durationMs; step->setDuration(durationMs); step->updateThumbnail(); // update error messages _mainWindow->updateProcessMessages(); } } } // make sure the progress bar gets filled updateProgress(100); counter++; } if(_stopExecution) return; // update images _mainWindow->imageViewer()->updateImage(); _mainWindow->imageViewer()->showProcessDuration(totalDurationMs); // update process graph _mainWindow->updateGraphicsView(); _mainWindow->unlockScene(); _isRunning = false; _currentStep = NULL; // if sequence, then run execute next step /*if(_sequenceCount > 0) { // notify GUI emit sequenceChanged(_sequenceIndex, _sequenceCount); if(_isSequenceRunning) { //setParamsHaveChanged(); _mainWindow->execute(true); } } // find sequence processes //bool graphNeedsUpdate = false; for(auto it = _scene->steps()->begin(); it < _scene->steps()->end(); ++it) { IPProcessStep* step = (IPProcessStep*) *it; IPLProcess* process = step->process(); if(process->isSequence()) { process->requestUpdate(); propertyChanged(process); requestUpdate(); } }*/ //if(_updateID > _currentUpdateID) // _mainWindow->execute(false); // only for testing the camera //if(graphNeedsUpdate) // _mainWindow->execute(false); _updateNeeded = false; // call afterProcessing of all steps which were executed this time // processes like the camera might request another execution QListIterator<IPProcessStep *> it2(_processList); while (it2.hasNext()) { IPProcessStep* step = it2.next(); step->process()->afterProcessing(); } }