[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs/kio/kio
From: Andreas Hartmetz <ahartmetz () gmail ! com>
Date: 2010-01-30 7:29:10
Message-ID: 1264836550.345558.12114.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1082240 by ahartmetz:
- Expose job priorities by API (and document them)
- Fix a memory leak in ProtoQueue::changeJobPriority() in an error case,
setting the priority of a connected-slave (or otherwise not scheduled)
job.
I was aware that QHash::operator[] can create the object but somehow I
considered the error case not a problem, which was of course wrong.
- In the same method, remove wrong logic concerning needReinsert; don't try
to be too clever and just compare lowestSerial() of the HostQueue before
and after reinserting the job there. This is correct, no assertion needed.
M +23 -12 scheduler.cpp
M +13 -4 scheduler.h
--- trunk/KDE/kdelibs/kio/kio/scheduler.cpp #1082239:1082240
@@ -73,7 +73,8 @@
int SerialPicker::changedPrioritySerial(int oldSerial, int newPriority) const
{
- Q_ASSERT(newPriority >= -5 && newPriority <= 5);
+ Q_ASSERT(newPriority >= -10 && newPriority <= 10);
+ newPriority = qBound(-10, newPriority, 10);
int unbiasedSerial = oldSerial % m_jobsPerPriority;
return unbiasedSerial + newPriority * m_jobsPerPriority;
}
@@ -456,22 +457,21 @@
ensureNoDuplicates(&m_queuesBySerial);
}
-void ProtoQueue::changeJobPriority(SimpleJob *job, int newPriority)
+void ProtoQueue::changeJobPriority(SimpleJob *job, int newPrio)
{
SimpleJobPrivate *jobPriv = SimpleJobPrivate::get(job);
- HostQueue &hq = m_queuesByHostname[jobPriv->m_url.host()];
- if (hq.isJobRunning(job)) {
+ QHash<QString, HostQueue>::Iterator it = m_queuesByHostname.find(jobPriv->m_url.host());
+ if (it == m_queuesByHostname.end()) {
return;
}
+ HostQueue &hq = it.value();
const int prevLowestSerial = hq.lowestSerial();
- if (!hq.removeJob(job)) {
+ if (hq.isJobRunning(job) || !hq.removeJob(job)) {
return;
}
- const int oldSerial = jobPriv->m_schedSerial;
- jobPriv->m_schedSerial = m_serialPicker.changedPrioritySerial(oldSerial, newPriority);
- const bool needReinsert = prevLowestSerial == oldSerial;
+ jobPriv->m_schedSerial = m_serialPicker.changedPrioritySerial(jobPriv->m_schedSerial, newPrio);
hq.queueJob(job);
- Q_ASSERT(needReinsert || hq.lowestSerial() == prevLowestSerial);
+ const bool needReinsert = hq.lowestSerial() != prevLowestSerial;
// the host queue might be absent from m_queuesBySerial because the connections per host limit
// for that host has been reached.
if (needReinsert && m_queuesBySerial.remove(prevLowestSerial)) {
@@ -687,6 +687,7 @@
void doJob(SimpleJob *job);
void scheduleJob(SimpleJob *job);
+ void setJobPriority(SimpleJob *job, int priority);
void cancelJob(SimpleJob *job);
void jobFinished(KIO::SimpleJob *job, KIO::Slave *slave);
void putSlaveOnHold(KIO::SimpleJob *job, const KUrl &url);
@@ -776,6 +777,11 @@
schedulerPrivate->scheduleJob(job);
}
+void Scheduler::setJobPriority(SimpleJob *job, int priority)
+{
+ schedulerPrivate->setJobPriority(job, priority);
+}
+
void Scheduler::cancelJob(SimpleJob *job)
{
schedulerPrivate->cancelJob(job);
@@ -904,11 +910,16 @@
void SchedulerPrivate::scheduleJob(SimpleJob *job)
{
kDebug(7006) << job;
- const QString protocol = SimpleJobPrivate::get(job)->m_protocol;
- ProtoQueue *proto = protoQ(protocol);
- proto->changeJobPriority(job, 1);
+ setJobPriority(job, 1);
}
+void SchedulerPrivate::setJobPriority(SimpleJob *job, int priority)
+{
+ kDebug(7006) << job << priority;
+ ProtoQueue *proto = protoQ(SimpleJobPrivate::get(job)->m_protocol);
+ proto->changeJobPriority(job, priority);
+}
+
void SchedulerPrivate::cancelJob(SimpleJob *job)
{
// this method is called all over the place in job.cpp, so just do this check here to avoid
--- trunk/KDE/kdelibs/kio/kio/scheduler.h #1082239:1082240
@@ -121,14 +121,23 @@
static void doJob(SimpleJob *job);
/**
- * Calling ths function makes that @p job gets scheduled for later
- * execution, if multiple jobs are registered it might wait for
- * other jobs to finish.
+ * Schedules @p job scheduled for later
+ * execution. This just sets the job's priority to 1 now.
* @param job the job to schedule
*/
- static void scheduleJob(SimpleJob *job);
+ KDE_DEPRECATED static void scheduleJob(SimpleJob *job);
/**
+ * Changes the priority of @p job; jobs of the same priority run in the order in which
+ * they were created. Jobs of lower numeric priority always run before any
+ * waiting jobs of higher numeric priority. The range of priority is -10 to 10,
+ * the default priority of jobs is 0.
+ * @param job the job to change
+ * @param priority new priority of @p job, lower runs earlier
+ */
+ static void setJobPriority(SimpleJob *job, int priority);
+
+ /**
* Stop the execution of a job.
* @param job the job to cancel
*/
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic