void Installer::UpdateProgress() { Job *j = this->CurrentJob(); if (this->window == NULL) return; Stage s = this->GetStage(); if (j != NULL && (s == DOWNLOADING || s == INSTALLING)) { double progress = j->GetProgress(); gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR(this->progressBar), progress); std::ostringstream text; if (s == INSTALLING) text << "Installing "; else text << "Downloading "; text << "package " << j->Index() << " of " << Job::total; gtk_label_set_text(GTK_LABEL(this->downloadingLabel), text.str().c_str()); } else if (s == PREINSTALL) { gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR(this->progressBar), 1.0); } }
void setup( const Record & record, const QModelIndex & idx ) { RecordItem::setup(record,idx); Job j = JobAssignment(record).job(); if( j.isRecord() ) services = j.jobServices().services().services().join(","); }
//Same as make_job_from_cin but everything is processed from an istream instead of user //input. See above for more details and comments explaining code segments bool Scheduler::make_job_from_line(istream &inFile) { int pid; int execTime; int resources; inFile >> pid; inFile >> execTime; inFile >> resources; Job *j = jobs.find(pid); win.clear_console(); if (execTime <= 0) { return file_error("Eecution time must be positive", pid, inFile); } else if (resources > MAX_MEMORY) { return file_error("Cannot use more than MAX MEMORY.", pid, inFile); } else if (resources < 0) { return file_error("Resources cannot be negative.", pid, inFile); } else if (j != NULL && j->get_status() != Job::LATENT) { return file_error("job already exists", pid, inFile); } else if (j == NULL) { j = new Job(pid); jobs.insert(j); } j->prepare(execTime, resources); //(see details above) read_dependencies(j, true, inFile); if (j->no_dependencies()) waitingOnMem.push(j); j->set_clock_insert(runClock); win.feed_bar("Created new job PID #%d", pid); return true; }
void LaunchDaemon::_HandleGetLaunchTargetInfo(BMessage* message) { uid_t user = _GetUserID(message); if (user < 0) return; const char* name = message->GetString("name"); Target* target = FindTarget(name); if (target == NULL && !fUserMode) { _ForwardEventMessage(user, message); return; } BMessage info(uint32(target != NULL ? B_OK : B_NAME_NOT_FOUND)); if (target != NULL) { _GetBaseJobInfo(target, info); for (JobMap::iterator iterator = fJobs.begin(); iterator != fJobs.end(); iterator++) { Job* job = iterator->second; if (job->Target() == target) info.AddString("job", job->Name()); } } message->SendReply(&info); }
void LaunchDaemon::_HandleEnableLaunchJob(BMessage* message) { uid_t user = _GetUserID(message); if (user < 0) return; const char* name = message->GetString("name"); bool enable = message->GetBool("enable"); Job* job = FindJob(name); if (job == NULL) { Session* session = FindSession(user); if (session != NULL) { // Forward request to user launch_daemon if (session->Daemon().SendMessage(message) == B_OK) return; } BMessage reply(B_NAME_NOT_FOUND); message->SendReply(&reply); return; } job->SetEnabled(enable); BMessage reply((uint32)B_OK); message->SendReply(&reply); }
void *install_thread_f(gpointer data) { Installer* inst = (Installer*) data; std::vector<Job*>& jobs = inst->GetJobs(); try { for (size_t i = 0; i < jobs.size(); i++) { Job *j = jobs.at(i); inst->SetCurrentJob(j); j->Unzip(); } } catch (std::exception& e) { std::string message = e.what(); inst->SetError(message); } catch (std::string& e) { inst->SetError(e); } catch (...) { std::string message = "Unknown error"; inst->SetError(message); } inst->SetRunning(false); inst->SetCurrentJob(NULL); return NULL; }
void intermediate(Job &job, results &result) { auto const start_time(std::chrono::system_clock::now()); for (unsigned partition=0; partition<job.number_of_partitions(); ++partition) job.run_intermediate_results_shuffle(partition); result.shuffle_runtime = std::chrono::system_clock::now() - start_time; }
void* JobPoolWorker::Entry() { #ifdef LINUX XInitThreads(); #endif while ( !stopped ) { // Did we get a request to terminate? if (TestDestroy()) break; Job *job = GetJob(); if (job) { // Call user's implementation for processing request ProcessJob(job); if (job->DeleteWhenComplete()) { delete job; } job = NULL; } else { std::unique_lock<std::mutex> mutLock(*lock); if (idleThreads > 5) { break; } } } std::unique_lock<std::mutex> mutLock(*lock); numThreads--; return NULL; }
void *submissionThread(int threadID) { int rate = generateRandom(MIN_CREATION_RATE, MAX_CREATION_RATE); printf("Submission thread %d creating jobs every %d seconds\n", threadID, rate); int t = currentTime(); int i = 0; while (jobCounter != MAX_JOBS_PER_THREAD * NUMBER_OF_SUBMISSION_THREADS - 1) { if (currentTime() > t + rate && i < MAX_JOBS_PER_THREAD) { t = currentTime(); Job job = createRandomJob(); //job.printJob(&job); if (job.currentPhase(&job).type == CPU_PHASE) { cpuQueue.enqueue(&cpuQueue, job); printf("Job %d put on CPU Queue by Submission Thread %d\n", job.id, threadID); } else if (job.currentPhase(&job).type == IO_PHASE) { ioQueue.enqueue(&ioQueue, job); printf("Job %d put on IO Queue by Submission Thread %d\n", job.id, threadID); } i++; } else { if (finishedQueue.getSize(&finishedQueue) > 0) { Job job = finishedQueue.dequeue(&finishedQueue); printf("Job %d taken off of Finished Queue by Submission Thread %d\n", job.id, threadID); job.printJob(&job); jobCounter++; printf("Jobs processed: %d\n", jobCounter + 1); if (jobCounter == MAX_JOBS_PER_THREAD * NUMBER_OF_SUBMISSION_THREADS - 1) { break; } } } } }
void ProgressTree2::cancelClicked() { CancelPushButton* pb = static_cast<CancelPushButton*>(QObject::sender()); pb->setEnabled(false); Job* job = getJob(*pb->item); job->cancel(); }
PSchedule Schedule :: scheduleEarly(ActiveList *activeList, const vector<Resource *> *resources) { PSchedule schedule(new Schedule(activeList, resources)); schedule->_type = ScheduleTypeEarly; for (int i=0; i<activeList->size(); i++) { Job *job = (*activeList)[i]; schedule->_starts[job] = 0; for (auto &predecessor : *job->predecessors()) { schedule->_starts[job] = max(schedule->start(job), schedule->end(predecessor)); } for (int time = 0; time < job->duration(); time++) { for (auto &pResourceAmount : *job->resourceAmounts()) { if (schedule->resourceRemain(pResourceAmount.first, schedule->start(job) + time) < pResourceAmount.second) { schedule->_starts[job] += time + 1; time = -1; break; } } } schedule->reduceResourceRemain(job); } return schedule; }
/*! * \brief Funcao que executa a Shell. */ void shooSH_run (void) { Job* job; Parser p; Executor executor; bool exited = false; while (!exited) { std::cout << "shooSH> "; job = p.parseLine (); history.push_back (job->getCommand()); if (job->hasFailed ()) { std::cout << "Erro de sintaxe" << std::endl; } else { if (!(job->isNop()||job->hasExited())) { if (!job->hasPipe()) { if (executeBuiltin (job->getProcess(0)) == -1) { job->setID (++currID); jobList.push_back (job); executor.execute (job); } } else { job->setID (++currID); jobList.push_back (job); executor.execute (job); } } else { exited = job->hasExited(); } } job = NULL; } shooSH_clean(); }
bool JobServerJobLogConsumer::DestroyClassAd(const char *_key) { // ignore the marker if (strcmp(_key,"0.0") == 0) { return true; } dprintf ( D_FULLDEBUG, "JobServerJobLogConsumer::DestroyClassAd - key '%s'\n", _key); JobCollectionType::iterator g_element = g_jobs.find(_key); if (g_jobs.end() == g_element) { dprintf(D_ALWAYS, "error reading job queue log: no such job found for key '%s'\n", _key); return false; } Job* job = (*g_element).second; // Destroy will figure out the submission decrement if (job->destroy()) { delete job; job = NULL; g_jobs.erase(g_element); } return true; }
void ListView::dropEvent(QDropEvent *event) { const QMimeData *mimeData = event->mimeData(); QStringList imagePaths; QList<QUrl> imageUrls = mimeData->urls(); QList<QUrl>::const_iterator end = imageUrls.constEnd(); for (QList<QUrl>::const_iterator count = imageUrls.constBegin(); count != end; count++) { QString path = (*count).toLocalFile(); if (!path.isEmpty() && path.contains(GCore::Data::self()->supportedFormats())) imagePaths << path; } QString image = imagePaths.first(); image.remove(QRegExp("^.+/")); QString path = imagePaths.first(); path.remove(image); QStringList pictures = imagePaths; pictures.replaceInStrings(path, QString()); QAction *choice = Data::self()->dropContextMenu()->exec(mapToGlobal(event->pos())); if (!choice) return; if (choice->data().toInt() == 0) { NewGalleryWizard *wizard = new NewGalleryWizard(path, pictures, this); wizard->show(); } else if (choice->data().toInt() == 1) { Job job = JobManager::self()->addImages(rootIndex(), imagePaths); connect(job.jobPtr(), SIGNAL(progress(int, int, const QString&, const QImage&)), GCore::Data::self()->imageAddProgress(), SLOT(setProgress(int, int, const QString&, const QImage&))); }
void MIDI_Fighter::loadConfig(){ FILE * fd = NULL; fd = fopen(CONFIG_FILE, "r"); if (fd != NULL){ //TODO: Load the file and do things } else{ LOG(ERR, "MIDIFighter", "Error loading MIDIFighter config file. Reverting to hex codes"); //HACK: test string loader Job* tmp = new Job(); tmp->addAction(new Action_string("Hello World!\\VK_RETURN;")); //HACK: end test for (int j = 0; j < NUM_BANKS; j++){ for (int i = 0; i < BTNS_PER_BANK; i++){ if (i == 0){ banks[j].btn[i] = tmp; } else{ banks[j].btn[i] = new Job(); banks[j].btn[i]->addAction(new Action_key(decToHex(i), true)); banks[j].btn[i]->addAction(new Action_key(decToHex(i), false)); } } } return; } }
Job createRandomJob() { int numberOfPhases = generateRandom(MIN_NUMBER_OF_PHASES, MAX_NUMBER_OF_PHASES); Phase phases[numberOfPhases]; int i = 0; PhaseType type; for (i = 0; i < numberOfPhases; i++) { int duration = generateRandom(1, MAX_DURATION); Phase phase; phase.duration = duration; if (type == CPU_PHASE) { type = IO_PHASE; } else if (type == IO_PHASE) { type = CPU_PHASE; } else { type = duration % 2 == 0 ? CPU_PHASE : IO_PHASE; } phase.type = type; phases[i] = phase; } Job job = createJob(phases, numberOfPhases); printf("Created Job %d\n", job.id); job.printJob(&job); return job; }
void Installer::UpdateProgress() { Job *j = this->CurrentJob(); if (this->window == NULL) return; if (this->IsRunning() && j != NULL) { double progress = j->GetProgress(); gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR(this->bar), progress); std::ostringstream text; if (this->DownloadFinished()) text << "Installing "; else text << "Downloading "; text << "package " << j->Index() << " of " << Job::total; gtk_label_set_text(GTK_LABEL(this->label), text.str().c_str()); } else if (!this->IsRunning()) { gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR(this->bar), 1.0); } }
void workerThread(int threadID, PhaseType phaseType) { Queue *currentQueue = phaseType == CPU_PHASE ? &cpuQueue : &ioQueue; Queue *destinationQueue = phaseType == CPU_PHASE ? &ioQueue : &cpuQueue; char *currentPhaseTitle = phaseType == CPU_PHASE ? "CPU" : "IO"; char *nextPhaseTitle = phaseType == CPU_PHASE ? "IO" : "CPU"; while (jobCounter != MAX_JOBS_PER_THREAD * NUMBER_OF_SUBMISSION_THREADS - 1) { if (currentQueue->getSize(currentQueue) > 0) { Job job = currentQueue->dequeue(currentQueue); int duration = job.currentPhase(&job).duration; printf("Job %d taken off of %s Queue by %s Thread %d\n", job.id, currentPhaseTitle, currentPhaseTitle, threadID); printf("Job %d executing on %s Thread %d for %d seconds\n", job.id, currentPhaseTitle, threadID, duration); //job.printJob(&job); sleep(duration); job.nextPhase(&job); if (job.currentPhase(&job).type == FINISHED_PHASE) { printf("Job %d put on Finished Queue by %s Thread %d\n", job.id, currentPhaseTitle, threadID); finishedQueue.enqueue(&finishedQueue, job); } else { printf("Job %d put on %s Queue by %s Thread %d\n", job.id, nextPhaseTitle, currentPhaseTitle, threadID); destinationQueue->enqueue(destinationQueue, job); } } } }
//! Adds a new job after the current one void InputDialog::addNewJob() { capturePreviewTextChanges(); Job* job; if (m_currentJob) { job = new Job(*m_currentJob); job->setCoordinates("read"); job->setComment(""); }else { job = new Job(); } addJobToList(job); int index(m_jobs.indexOf(job)); if (index >= 0) m_ui.jobList->setCurrentIndex(index); // The default Molecule section is set to "read", but // for the first job we specify things explicitly. if (m_jobs.size() == 1) { qDebug() << "WARN: setting QChemJobInfo, not JobInfo"; //setJobInfo(m_jobInfo); setQChemJobInfo(m_qchemJobInfo); } }
void XournalScheduler::removeAllJobs() { XOJ_CHECK_TYPE(XournalScheduler); g_mutex_lock(&this->jobQueueMutex); for (int priority = JOB_PRIORITY_URGENT; priority < JOB_N_PRIORITIES; priority++) { int length = g_queue_get_length(this->jobQueue[priority]); for (int i = 0; i < length; i++) { Job* job = (Job*) g_queue_peek_nth(this->jobQueue[priority], i); JobType type = job->getType(); if (type == JOB_TYPE_PREVIEW || type == JOB_TYPE_RENDER) { job->deleteJob(); g_queue_remove(this->jobQueue[priority], job); job->unref(); } } } g_mutex_unlock(&this->jobQueueMutex); }
void reduce(Job &job, results &result) { auto const start_time(std::chrono::system_clock::now()); for (unsigned partition=0; partition<job.number_of_partitions(); ++partition) job.run_reduce_task(partition, result); result.reduce_runtime = std::chrono::system_clock::now() - start_time; }
void XournalScheduler::removeSource(void* source, JobType type, JobPriority priority) { XOJ_CHECK_TYPE(XournalScheduler); g_mutex_lock(&this->jobQueueMutex); int length = g_queue_get_length(this->jobQueue[priority]); for (int i = 0; i < length; i++) { Job* job = (Job*) g_queue_peek_nth(this->jobQueue[priority], i); if (job->getType() == type) { if (job->getSource() == source) { job->deleteJob(); g_queue_remove(this->jobQueue[priority], job); job->unref(); break; } } } // wait until the last job is done // we can be sure we don't access "source" finishTask(); g_mutex_unlock(&this->jobQueueMutex); }
/*! Initializes all jobs for the specified target (may be \c NULL). Jobs that cannot be initialized, and those that never will be due to conditions, will be removed from the list. */ void LaunchDaemon::_InitJobs(Target* target) { for (JobMap::iterator iterator = fJobs.begin(); iterator != fJobs.end();) { Job* job = iterator->second; JobMap::iterator remove = iterator++; if (job->Target() != target) continue; status_t status = B_NO_INIT; if (job->IsEnabled()) { // Filter out jobs that have a constant and failing condition if (job->Condition() == NULL || !job->Condition()->IsConstant(*this) || job->Condition()->Test(*this)) { std::set<BString> dependencies; status = job->Init(*this, dependencies); if (status == B_OK && job->Event() != NULL) status = job->Event()->Register(*this); } } if (status != B_OK) { if (status != B_NO_INIT) { // TODO: log error debug_printf("Init \"%s\" failed: %s\n", job->Name(), strerror(status)); } // Remove jobs that won't be used later on fJobs.erase(remove); delete job; } } }
bool XournalScheduler::existsSource(void* source, JobType type, JobPriority priority) { XOJ_CHECK_TYPE(XournalScheduler); bool exists = false; g_mutex_lock(&this->jobQueueMutex); int length = g_queue_get_length(this->jobQueue[priority]); for (int i = 0; i < length; i++) { Job* job = (Job*) g_queue_peek_nth(this->jobQueue[priority], i); if (job->getType() == type) { if (job->getSource() == source) { exists = true; break; } } } g_mutex_unlock(&this->jobQueueMutex); return exists; }
void CCMSDIntegrator::ParseCMSD(std::string filename) { CMSD::CCMSD doc = CMSD::CCMSD::LoadFromFile(filename); doc.SaveToFile((::ExeDirectory() + "Test1.xml").c_str(), true); //CMSD::CCMSD::DataSection d = doc.DataSection().first(); CMSD::CwhiteSpaceType root = doc.whiteSpace.first(); CMSD::CCMSDDocument cmsddocument = doc.CMSDDocument[0]; CMSD::CDataSectionType2 data = cmsddocument.DataSection[0]; for(int i=0; i< data.PartType.count() ; i++) { Part * apart ( (Part*) Part().CreateSave<Part>()); apart->Load(data.PartType[i].GetNode()); //std::vector<IObjectPtr> &someparts ( apart->objects()); //Part * part2=(Part *) someparts[0].get(); } for(int i=0; i< data.ProcessPlan.count() ; i++) { ProcessPlan * aplan ( (ProcessPlan *) IObject::CreateSave<ProcessPlan>()); aplan->Load(data.ProcessPlan[i].GetNode()); } for(int i=0; i< data.Resource.count() ; i++) { if(Cell::IsResourceCell(data.Resource[i].GetNode())) { Cell * acell( (Cell *) IObject::CreateSave<Cell>()); acell->Load(data.Resource[i].GetNode()); } else { Resource * aresource ((Resource *) IObject::CreateSave<Resource>()); aresource->Load(data.Resource[i].GetNode()); } } for(int i=0; i< data.Job.count() ; i++) { Job * ajob ( IObject::CreateSave<Job>() ); ajob->Load(data.Job[i].GetNode()); } for(int i=0; i< data.DistributionDefinition.count() ; i++) { Distribution * astat ( (Distribution *) IObject::CreateSave<Distribution>() ); astat->LoadDefinition(data.DistributionDefinition[i].GetNode()); } for(int i=0; i< data.Calendar.count() ; i++) { Calendar * calendar ( (Calendar *) IObject::CreateSave<Calendar>()); calendar->Load(data.Calendar[i].GetNode()); } for(int i=0; i< data.Layout.count() ; i++) { Layout * layout ((Layout *) IObject::CreateSave<Layout>()); layout->Load(data.Layout[i].GetNode()); } //CMSD::CInventoryItem inv = data.InventoryItem[0]; //inv.Location int j=0; }
Scheduler::~Scheduler() { XOJ_CHECK_TYPE(Scheduler); SDEBUG("Destroy scheduler\n", 0); if(this->jobRenderThreadTimerId) { g_source_remove(this->jobRenderThreadTimerId); this->jobRenderThreadTimerId = 0; } stop(); g_mutex_free(this->jobQueueMutex); g_mutex_free(this->jobRunningMutex); g_mutex_free(this->schedulerMutex); g_mutex_free(this->blockRenderMutex); g_cond_free(this->jobQueueCond); Job * job = NULL; while (job = getNextJobUnlocked()) { job->unref(); } if (this->blockRenderZoomTime) { g_free(this->blockRenderZoomTime); } XOJ_RELEASE_TYPE(Scheduler); }
// call OnFinish methods for completed jobs, and clean up Uint32 AsyncJobQueue::FinishJobs() { PROFILE_SCOPED() Uint32 finished = 0; const uint32_t numRunners = m_runners.size(); for( uint32_t i=0; i<numRunners ; ++i) { SDL_LockMutex(m_finishedLock[i]); if( m_finished[i].empty() ) { SDL_UnlockMutex(m_finishedLock[i]); continue; } Job *job = m_finished[i].front(); m_finished[i].pop_front(); SDL_UnlockMutex(m_finishedLock[i]); assert(job); // if its already been cancelled then its taken care of, so we just forget about it if(!job->cancelled) { job->UnlinkHandle(); job->OnFinish(); finished++; } delete job; } return finished; }
Job * Scheduler::getNextJobUnlocked(bool onlyNotRender, bool * hasRenderJobs) { XOJ_CHECK_TYPE(Scheduler); Job * job = NULL; for (int i = JOB_PRIORITY_URGENT; i < JOB_N_PRIORITIES; i++) { if(onlyNotRender) { for(GList * l = this->jobQueue[i]->head; l != NULL; l = l->next) { job = (Job *) l->data; if(job->getType() != JOB_TYPE_RENDER) { g_queue_delete_link(this->jobQueue[i], l); return job; } else if(hasRenderJobs) { *hasRenderJobs = true; } } } else { job = (Job *) g_queue_pop_head(this->jobQueue[i]); if (job) { return job; } } } return NULL; }
//Take a list of PIDs from cin. For each PID, check the "jobs" JHT to see //whether it is already Job::COMPLETE. If it isn't already Job::COMPLETE, add it to a //JHT called dependencies. Also, append the job pointer j to that PID's successor //list. When finished, return the dependencies JHT. (NOTE: there are two different //uses of the JHT class here) void Scheduler::read_dependencies(Job *j, bool externalFile, istream &inFile) { int pid = -2; Job *dependentJob; if (!externalFile) { win.menu_bar("Enter dependencies, enter -1 when finished: "); } for (int i = 1; true; i++) { //runs for true because sentinel breaks loop pid = get_dependent_pid(externalFile, i, inFile); if (pid == -1) {break;} //just using a simple -1 sentinel dependentJob = jobs.find(pid); //If the job specified does not already exist in jobs, we create a new latent job if (dependentJob == NULL) { dependentJob = new Job(pid); jobs.insert(dependentJob); } //If the dependentJob is already complete, we just ignore that input entirely if (dependentJob->get_status() != Job::COMPLETE) { j->add_dependency(dependentJob); //insert job into the dependencies table dependentJob->add_successor(j); //and add to give job's successors //Now we run the deep search function on the new dependent job. //Note that we pass the second parameter as 1 + j's current longest chain, //which might not necessarily be 0 if it was initialized out of a latent state if (CHAIN_WEIGHTING) { deep_search_update(dependentJob, j->get_longest_chain() + 1); } } } }
job_wait_status Worker::WaitForJob(Job* waitingJob, const JobKey& key) { AutoLocker<Worker> locker(this); // don't wait when the game is over anyway if (fTerminating || waitingJob->State() == JOB_STATE_ABORTED) return JOB_DEPENDENCY_ABORTED; Job* job = fJobs.Lookup(key); if (job == NULL) return JOB_DEPENDENCY_NOT_FOUND; waitingJob->SetWaitStatus(JOB_DEPENDENCY_ACTIVE); waitingJob->SetDependency(job); job->DependentJobs().Add(waitingJob); // TODO: Continuations would be nice. For the time being we have to use // recursion. Disadvantages are that we'll use more stack and that aborting // a job waiting for a dependency won't abort the job before the dependency // is done. locker.Unlock(); _ProcessJobs(waitingJob); locker.Lock(); // ignore the actual wait status when the game is over anyway if (fTerminating || waitingJob->State() == JOB_STATE_ABORTED) return JOB_DEPENDENCY_ABORTED; return waitingJob->WaitStatus(); }