Changeset View
Changeset View
Standalone View
Standalone View
src/core/scheduler.cpp
Show First 20 Lines • Show All 205 Lines • ▼ Show 20 Line(s) | 198 | { | |||
---|---|---|---|---|---|
206 | } | 206 | } | ||
207 | return false; | 207 | return false; | ||
208 | } | 208 | } | ||
209 | 209 | | |||
210 | QList<Slave *> HostQueue::allSlaves() const | 210 | QList<Slave *> HostQueue::allSlaves() const | ||
211 | { | 211 | { | ||
212 | QList<Slave *> ret; | 212 | QList<Slave *> ret; | ||
213 | ret.reserve(m_runningJobs.size()); | 213 | ret.reserve(m_runningJobs.size()); | ||
214 | Q_FOREACH (SimpleJob *job, m_runningJobs) { | 214 | for (SimpleJob *job : m_runningJobs) { | ||
dfaure: qAsConst not needed, this method is const | |||||
ahmadsamir: (... and m_runningJobs is a member var). | |||||
215 | Slave *slave = jobSlave(job); | 215 | Slave *slave = jobSlave(job); | ||
216 | Q_ASSERT(slave); | 216 | Q_ASSERT(slave); | ||
217 | ret.append(slave); | 217 | ret.append(slave); | ||
218 | } | 218 | } | ||
219 | return ret; | 219 | return ret; | ||
220 | } | 220 | } | ||
221 | 221 | | |||
222 | ConnectedSlaveQueue::ConnectedSlaveQueue() | 222 | ConnectedSlaveQueue::ConnectedSlaveQueue() | ||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Line(s) | |||||
291 | 291 | | |||
292 | bool ConnectedSlaveQueue::removeSlave(Slave *slave) | 292 | bool ConnectedSlaveQueue::removeSlave(Slave *slave) | ||
293 | { | 293 | { | ||
294 | QHash<Slave *, PerSlaveQueue>::Iterator it = m_connectedSlaves.find(slave); | 294 | QHash<Slave *, PerSlaveQueue>::Iterator it = m_connectedSlaves.find(slave); | ||
295 | if (it == m_connectedSlaves.end()) { | 295 | if (it == m_connectedSlaves.end()) { | ||
296 | return false; | 296 | return false; | ||
297 | } | 297 | } | ||
298 | PerSlaveQueue &jobs = it.value(); | 298 | PerSlaveQueue &jobs = it.value(); | ||
299 | Q_FOREACH (SimpleJob *job, jobs.waitingList) { | 299 | // we need a copy as kill() ends up removing the job from waitingList | ||
300 | const QList <SimpleJob *> waitingJobs = jobs.waitingList; | ||||
301 | for (SimpleJob *job : waitingJobs) { | ||||
I'm afraid that kill() ends up removing the job from waitingList. I would iterate over a copy to be safe. dfaure: I'm afraid that kill() ends up removing the job from waitingList. I would iterate over a copy… | |||||
300 | // ### for compatibility with the old scheduler we don't touch the running job, if any. | 302 | // ### for compatibility with the old scheduler we don't touch the running job, if any. | ||
301 | // make sure that the job doesn't call back into Scheduler::cancelJob(); this would | 303 | // make sure that the job doesn't call back into Scheduler::cancelJob(); this would | ||
302 | // a) crash and b) be unnecessary because we clean up just fine. | 304 | // a) crash and b) be unnecessary because we clean up just fine. | ||
303 | SimpleJobPrivate::get(job)->m_schedSerial = 0; | 305 | SimpleJobPrivate::get(job)->m_schedSerial = 0; | ||
304 | job->kill(); | 306 | job->kill(); | ||
305 | } | 307 | } | ||
306 | m_connectedSlaves.erase(it); | 308 | m_connectedSlaves.erase(it); | ||
307 | m_runnableSlaves.remove(slave); | 309 | m_runnableSlaves.remove(slave); | ||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | |||||
357 | } | 359 | } | ||
358 | 360 | | |||
359 | static void ensureNoDuplicates(QMap<int, HostQueue *> *queuesBySerial) | 361 | static void ensureNoDuplicates(QMap<int, HostQueue *> *queuesBySerial) | ||
360 | { | 362 | { | ||
361 | Q_UNUSED(queuesBySerial); | 363 | Q_UNUSED(queuesBySerial); | ||
362 | #ifdef SCHEDULER_DEBUG | 364 | #ifdef SCHEDULER_DEBUG | ||
363 | // a host queue may *never* be in queuesBySerial twice. | 365 | // a host queue may *never* be in queuesBySerial twice. | ||
364 | QSet<HostQueue *> seen; | 366 | QSet<HostQueue *> seen; | ||
365 | Q_FOREACH (HostQueue *hq, *queuesBySerial) { | 367 | auto it = queuesBySerial->cbegin(); | ||
366 | Q_ASSERT(!seen.contains(hq)); | 368 | for (; it != queuesBySerial->cend(); ++it) { | ||
367 | seen.insert(hq); | 369 | Q_ASSERT(!seen.contains(it.value())); | ||
370 | seen.insert(it.value()); | ||||
368 | } | 371 | } | ||
369 | #endif | 372 | #endif | ||
370 | } | 373 | } | ||
371 | 374 | | |||
372 | static void verifyRunningJobsCount(QHash<QString, HostQueue> *queues, int runningJobsCount) | 375 | static void verifyRunningJobsCount(QHash<QString, HostQueue> *queues, int runningJobsCount) | ||
373 | { | 376 | { | ||
374 | Q_UNUSED(queues); | 377 | Q_UNUSED(queues); | ||
375 | Q_UNUSED(runningJobsCount); | 378 | Q_UNUSED(runningJobsCount); | ||
376 | #ifdef SCHEDULER_DEBUG | 379 | #ifdef SCHEDULER_DEBUG | ||
dfaure: Did you try enabling this to make sure your ported code compiles? | |||||
Yes, I did. (I, like everyone else, hate to be embarrassed, so I always make sure it builds and passes unittests whenever I change anything except maybe comments :)). ahmadsamir: Yes, I did. (I, like everyone else, hate to be embarrassed, so I always make sure it builds and… | |||||
377 | int realRunningJobsCount = 0; | 380 | int realRunningJobsCount = 0; | ||
378 | Q_FOREACH (const HostQueue &hq, *queues) { | 381 | auto it = queues->cbegin(); | ||
379 | realRunningJobsCount += hq.runningJobsCount(); | 382 | for (; it != queues->cend(); ++it) { | ||
383 | realRunningJobsCount += it.value().runningJobsCount(); | ||||
380 | } | 384 | } | ||
381 | Q_ASSERT(realRunningJobsCount == runningJobsCount); | 385 | Q_ASSERT(realRunningJobsCount == runningJobsCount); | ||
382 | 386 | | |||
383 | // ...and of course we may never run the same job twice! | 387 | // ...and of course we may never run the same job twice! | ||
384 | QSet<SimpleJob *> seenJobs; | 388 | QSet<SimpleJob *> seenJobs; | ||
385 | Q_FOREACH (const HostQueue &hq, *queues) { | 389 | auto it2 = queues->cbegin(); | ||
386 | Q_FOREACH (SimpleJob *job, hq.runningJobs()) { | 390 | for (; it2 != queues->cend(); ++it2) { | ||
391 | for (SimpleJob *job : it2.value().runningJobs()) { | ||||
387 | Q_ASSERT(!seenJobs.contains(job)); | 392 | Q_ASSERT(!seenJobs.contains(job)); | ||
388 | seenJobs.insert(job); | 393 | seenJobs.insert(job); | ||
389 | } | 394 | } | ||
390 | } | 395 | } | ||
391 | #endif | 396 | #endif | ||
392 | } | 397 | } | ||
393 | 398 | | |||
394 | ProtoQueue::ProtoQueue(int maxSlaves, int maxSlavesPerHost) | 399 | ProtoQueue::ProtoQueue(int maxSlaves, int maxSlavesPerHost) | ||
▲ Show 20 Lines • Show All 163 Lines • ▼ Show 20 Line(s) | 561 | { | |||
558 | const bool removedUnconnected = m_slaveKeeper.removeSlave(slave); | 563 | const bool removedUnconnected = m_slaveKeeper.removeSlave(slave); | ||
559 | Q_ASSERT(!(removedConnected && removedUnconnected)); | 564 | Q_ASSERT(!(removedConnected && removedUnconnected)); | ||
560 | return removedConnected || removedUnconnected; | 565 | return removedConnected || removedUnconnected; | ||
561 | } | 566 | } | ||
562 | 567 | | |||
563 | QList<Slave *> ProtoQueue::allSlaves() const | 568 | QList<Slave *> ProtoQueue::allSlaves() const | ||
564 | { | 569 | { | ||
565 | QList<Slave *> ret(m_slaveKeeper.allSlaves()); | 570 | QList<Slave *> ret(m_slaveKeeper.allSlaves()); | ||
566 | Q_FOREACH (const HostQueue &hq, m_queuesByHostname) { | 571 | auto it = m_queuesByHostname.cbegin(); | ||
567 | ret.append(hq.allSlaves()); | 572 | for (; it != m_queuesByHostname.cend(); ++it) { | ||
573 | ret.append(it.value().allSlaves()); | ||||
568 | } | 574 | } | ||
569 | ret.append(m_connectedSlaveQueue.allSlaves()); | 575 | ret.append(m_connectedSlaveQueue.allSlaves()); | ||
570 | return ret; | 576 | return ret; | ||
571 | } | 577 | } | ||
572 | 578 | | |||
573 | //private slot | 579 | //private slot | ||
574 | void ProtoQueue::startAJob() | 580 | void ProtoQueue::startAJob() | ||
575 | { | 581 | { | ||
576 | ensureNoDuplicates(&m_queuesBySerial); | 582 | ensureNoDuplicates(&m_queuesBySerial); | ||
577 | verifyRunningJobsCount(&m_queuesByHostname, m_runningJobsCount); | 583 | verifyRunningJobsCount(&m_queuesByHostname, m_runningJobsCount); | ||
578 | 584 | | |||
579 | #ifdef SCHEDULER_DEBUG | 585 | #ifdef SCHEDULER_DEBUG | ||
580 | //qDebug() << "m_runningJobsCount:" << m_runningJobsCount; | 586 | //qDebug() << "m_runningJobsCount:" << m_runningJobsCount; | ||
581 | Q_FOREACH (const HostQueue &hq, m_queuesByHostname) { | 587 | auto it = m_queuesByHostname.cbegin(); | ||
582 | Q_FOREACH (SimpleJob *job, hq.runningJobs()) { | 588 | for (; it != m_queuesByHostname.cend(); ++it) { | ||
589 | const QList<KIO::SimpleJob *> list = it.value().runningJobs(); | ||||
590 | for (SimpleJob *job : list) { | ||||
583 | //qDebug() << SimpleJobPrivate::get(job)->m_url; | 591 | //qDebug() << SimpleJobPrivate::get(job)->m_url; | ||
584 | } | 592 | } | ||
585 | } | 593 | } | ||
586 | #endif | 594 | #endif | ||
587 | if (m_runningJobsCount >= m_maxConnectionsTotal) { | 595 | if (m_runningJobsCount >= m_maxConnectionsTotal) { | ||
588 | #ifdef SCHEDULER_DEBUG | 596 | #ifdef SCHEDULER_DEBUG | ||
589 | //qDebug() << "not starting any jobs because maxConnectionsTotal has been reached."; | 597 | //qDebug() << "not starting any jobs because maxConnectionsTotal has been reached."; | ||
590 | #endif | 598 | #endif | ||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | 667 | : q(new Scheduler()), | |||
662 | m_ignoreConfigReparse(false) | 670 | m_ignoreConfigReparse(false) | ||
663 | { | 671 | { | ||
664 | } | 672 | } | ||
665 | 673 | | |||
666 | ~SchedulerPrivate() | 674 | ~SchedulerPrivate() | ||
667 | { | 675 | { | ||
668 | delete q; | 676 | delete q; | ||
669 | q = nullptr; | 677 | q = nullptr; | ||
670 | Q_FOREACH (ProtoQueue *p, m_protocols) { | 678 | for (ProtoQueue *p : qAsConst(m_protocols)) { | ||
671 | Q_FOREACH (Slave *slave, p->allSlaves()) { | 679 | const QList<KIO::Slave *> list = p->allSlaves(); | ||
680 | for (Slave *slave : list) { | ||||
672 | slave->kill(); | 681 | slave->kill(); | ||
673 | } | 682 | } | ||
674 | } | 683 | } | ||
675 | qDeleteAll(m_protocols); | 684 | qDeleteAll(m_protocols); | ||
676 | } | 685 | } | ||
677 | Scheduler *q; | 686 | Scheduler *q; | ||
678 | 687 | | |||
679 | Slave *m_slaveOnHold; | 688 | Slave *m_slaveOnHold; | ||
▲ Show 20 Lines • Show All 239 Lines • ▼ Show 20 Line(s) | 927 | QHash<QString, ProtoQueue *>::ConstIterator it = proto.isEmpty() ? m_protocols.constBegin() : | |||
919 | m_protocols.constFind(proto); | 928 | m_protocols.constFind(proto); | ||
920 | // not found? | 929 | // not found? | ||
921 | if (it == m_protocols.constEnd()) { | 930 | if (it == m_protocols.constEnd()) { | ||
922 | return; | 931 | return; | ||
923 | } | 932 | } | ||
924 | QHash<QString, ProtoQueue *>::ConstIterator endIt = proto.isEmpty() ? m_protocols.constEnd() : | 933 | QHash<QString, ProtoQueue *>::ConstIterator endIt = proto.isEmpty() ? m_protocols.constEnd() : | ||
925 | it + 1; | 934 | it + 1; | ||
926 | for (; it != endIt; ++it) { | 935 | for (; it != endIt; ++it) { | ||
927 | Q_FOREACH (Slave *slave, (*it)->allSlaves()) { | 936 | const QList<KIO::Slave *> list = it.value()->allSlaves(); | ||
937 | for (Slave *slave : list) { | ||||
928 | slave->send(CMD_REPARSECONFIGURATION); | 938 | slave->send(CMD_REPARSECONFIGURATION); | ||
929 | slave->resetHost(); | 939 | slave->resetHost(); | ||
930 | } | 940 | } | ||
931 | } | 941 | } | ||
932 | } | 942 | } | ||
933 | 943 | | |||
934 | void SchedulerPrivate::slotSlaveOnHoldListChanged() | 944 | void SchedulerPrivate::slotSlaveOnHoldListChanged() | ||
935 | { | 945 | { | ||
▲ Show 20 Lines • Show All 383 Lines • Show Last 20 Lines |
qAsConst not needed, this method is const