bool JobList::schedule(ProcessList &p,unsigned int time) { if(hasJob() == false) return false; auto min = jlist.begin(); bool sign = false; for(auto i = min; i != jlist.end(); ++i) { unsigned int m = getUnusedMem(); if(i->stime <= time && i->memory <= m) { if(i->ntime <= min->ntime || min->memory > m) { min = i; sign = true; } } } if(!sign) return false; if(NULL == ( min->memAddr = mm_malloc(min->memory))) return false; p.insertJobB(*min); jlist.erase(min); return true; }
void AvatarJobManager::scheduleJob() { QMutexLocker(&mutex()); if (!IsJobRunning && hasJob()) // run it in next even cycle // this is for reccursion prevention, so we save on stack memory QTimer::singleShot(0, this, SLOT(runJob())); }
Contact AvatarJobManager::nextJob() { QMutexLocker(&mutex()); if (!hasJob()) return Contact::null; Contact job = *Jobs.constBegin(); Jobs.remove(job); return job; }
void AvatarJobManager::runJob() { QMutexLocker(&mutex()); if (IsJobRunning) return; if (!hasJob()) return; IsJobRunning = true; Contact contact = nextJob(); AvatarJobRunner *runner = new AvatarJobRunner(contact, this); connect(runner, SIGNAL(jobFinished(bool)), this, SLOT(jobFinished())); runner->runJob(); }