mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kio: prioritize some type of jobs and do not reuse slaves
turned out the some slaves, the file slave for one, is not ready for reusable action.. Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
df7257e308
commit
2abb4cf251
6 changed files with 24 additions and 65 deletions
|
@ -309,11 +309,8 @@ void SimpleJob::setRedirectionHandlingEnabled(bool handle)
|
|||
SimpleJob::~SimpleJob()
|
||||
{
|
||||
Q_D(SimpleJob);
|
||||
// last chance to remove this job from the scheduler!
|
||||
if (d->m_schedSerial) {
|
||||
kDebug(7007) << "Killing job" << this << "in destructor!" << kBacktrace();
|
||||
Scheduler::self()->cancelJob(this);
|
||||
}
|
||||
kDebug(7007) << "Killing job" << this << "in destructor!" << kBacktrace();
|
||||
Scheduler::self()->cancelJob(this);
|
||||
}
|
||||
|
||||
void SimpleJobPrivate::start(SlaveInterface *slave)
|
||||
|
@ -392,10 +389,8 @@ void SimpleJobPrivate::slaveDone()
|
|||
// Remove all signals between slave and job
|
||||
q->disconnect(m_slave);
|
||||
}
|
||||
// only finish a job once; Scheduler::jobFinished() resets schedSerial to zero.
|
||||
if (m_schedSerial) {
|
||||
Scheduler::self()->jobFinished(q, m_slave);
|
||||
}
|
||||
// only finish a job once
|
||||
Scheduler::self()->jobFinished(q, m_slave);
|
||||
}
|
||||
|
||||
void SimpleJob::slotFinished()
|
||||
|
@ -514,6 +509,7 @@ public:
|
|||
MkdirJobPrivate(const KUrl &url, int command, const QByteArray &packedArgs)
|
||||
: SimpleJobPrivate(url, command, packedArgs)
|
||||
{
|
||||
m_schedPrio = 1;
|
||||
}
|
||||
|
||||
KUrl m_redirectionURL;
|
||||
|
@ -650,6 +646,7 @@ public:
|
|||
inline StatJobPrivate(const KUrl &url, int command, const QByteArray &packedArgs)
|
||||
: SimpleJobPrivate(url, command, packedArgs), m_bSource(true), m_details(2)
|
||||
{
|
||||
m_schedPrio = 1;
|
||||
}
|
||||
|
||||
UDSEntry m_statResult;
|
||||
|
@ -1858,6 +1855,7 @@ public:
|
|||
recursive(_recursive), includeHidden(_includeHidden),
|
||||
m_prefix(prefix), m_displayPrefix(displayPrefix), m_processedEntries(0)
|
||||
{
|
||||
m_schedPrio = 1;
|
||||
}
|
||||
|
||||
bool recursive;
|
||||
|
|
|
@ -110,7 +110,7 @@ namespace KIO {
|
|||
*/
|
||||
SimpleJobPrivate(const KUrl& url, int command, const QByteArray &packedArgs)
|
||||
: m_slave(0), m_packedArgs(packedArgs), m_url(url), m_command(command),
|
||||
m_redirectionHandlingEnabled(true), m_schedSerial(0)
|
||||
m_redirectionHandlingEnabled(true), m_schedPrio(10)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ namespace KIO {
|
|||
bool m_redirectionHandlingEnabled;
|
||||
|
||||
// for use in KIO::Scheduler
|
||||
int m_schedSerial;
|
||||
int m_schedPrio;
|
||||
|
||||
/**
|
||||
* Forward signal from the slave.
|
||||
|
|
|
@ -28,9 +28,6 @@
|
|||
#include <QTextCodec>
|
||||
|
||||
static const int s_jobtimeout = 100; // ms
|
||||
static const int s_idletimeout = 5000; // ms
|
||||
// slaves may be idle for a certain time (1 minute) before they are killed
|
||||
static const int s_idleslavelifetime = 60000;
|
||||
|
||||
namespace KIO
|
||||
{
|
||||
|
@ -48,7 +45,6 @@ Scheduler::Scheduler(QObject *parent)
|
|||
{
|
||||
setObjectName("scheduler");
|
||||
connect(&m_jobtimer, SIGNAL(timeout()), this, SLOT(slotStartJob()));
|
||||
connect(&m_idletimer, SIGNAL(timeout()), this, SLOT(slotCheckSlaves()));
|
||||
}
|
||||
|
||||
Scheduler::~Scheduler()
|
||||
|
@ -67,31 +63,18 @@ void Scheduler::doJob(KIO::SimpleJob *job)
|
|||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
KIO::SimpleJobPrivate *const jobPriv = SimpleJobPrivate::get(job);
|
||||
jobPriv->m_schedSerial = 1;
|
||||
m_jobs.append(job);
|
||||
m_jobs.insert(jobPriv->m_schedPrio, job);
|
||||
kDebug(7006) << "queued job" << job->url();
|
||||
if (!m_jobtimer.isActive()) {
|
||||
m_jobtimer.start(s_jobtimeout);
|
||||
}
|
||||
if (!m_idletimer.isActive()) {
|
||||
m_idletimer.start(s_idletimeout);
|
||||
}
|
||||
}
|
||||
|
||||
void Scheduler::cancelJob(KIO::SimpleJob *job)
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
kDebug(7006) << "canceling job" << job->url();
|
||||
KIO::SimpleJobPrivate *const jobPriv = SimpleJobPrivate::get(job);
|
||||
KIO::SlaveInterface* slave = jobPriv->m_slave;
|
||||
if (slave) {
|
||||
slave->disconnect(job);
|
||||
slave->kill();
|
||||
}
|
||||
m_slaves.removeAll(slave);
|
||||
jobPriv->m_schedSerial = 0; // this marks the job as unscheduled again
|
||||
jobPriv->m_slave = nullptr;
|
||||
m_jobs.removeAll(job);
|
||||
jobFinished(job, jobPriv->m_slave);
|
||||
}
|
||||
|
||||
void Scheduler::jobFinished(KIO::SimpleJob *job, KIO::SlaveInterface *slave)
|
||||
|
@ -101,9 +84,10 @@ void Scheduler::jobFinished(KIO::SimpleJob *job, KIO::SlaveInterface *slave)
|
|||
KIO::SimpleJobPrivate *const jobPriv = SimpleJobPrivate::get(job);
|
||||
if (slave) {
|
||||
slave->disconnect(job);
|
||||
slave->setIdle();
|
||||
slave->kill();
|
||||
slave->deref();
|
||||
}
|
||||
jobPriv->m_schedSerial = 0; // this marks the job as unscheduled again
|
||||
m_slaves.removeAll(slave);
|
||||
jobPriv->m_slave = nullptr;
|
||||
m_jobs.removeAll(job);
|
||||
}
|
||||
|
@ -153,10 +137,6 @@ void Scheduler::slotStartJob()
|
|||
if (!itslave->isAlive()) {
|
||||
continue;
|
||||
}
|
||||
if (itslave->protocol() == protocol && itslave->idleTime() > 0) {
|
||||
slave = itslave;
|
||||
continue;
|
||||
}
|
||||
if (itslave->protocol() == protocol) {
|
||||
slaveForProtoCounter++;
|
||||
}
|
||||
|
@ -233,24 +213,6 @@ void Scheduler::slotStartJob()
|
|||
}
|
||||
}
|
||||
|
||||
void Scheduler::slotCheckSlaves()
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
QMutableListIterator<KIO::SlaveInterface*> iter(m_slaves);
|
||||
while (iter.hasNext()) {
|
||||
KIO::SlaveInterface* slave = iter.next();
|
||||
if (slave->idleTime() >= s_idleslavelifetime) {
|
||||
kDebug(7006) << "killing idle slave" << slave->pid() << slave->protocol();
|
||||
iter.remove();
|
||||
slave->kill();
|
||||
slave->deref();
|
||||
}
|
||||
}
|
||||
if (m_slaves.size() <= 0) {
|
||||
m_idletimer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include "moc_scheduler_p.cpp"
|
||||
|
|
|
@ -71,7 +71,6 @@ namespace KIO {
|
|||
private Q_SLOTS:
|
||||
void slotSlaveDied(KIO::SlaveInterface *slave);
|
||||
void slotStartJob();
|
||||
void slotCheckSlaves();
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(Scheduler)
|
||||
|
@ -80,7 +79,6 @@ namespace KIO {
|
|||
QList<KIO::SlaveInterface*> m_slaves;
|
||||
QList<KIO::SimpleJob*> m_jobs;
|
||||
QTimer m_jobtimer;
|
||||
QTimer m_idletimer;
|
||||
bool m_initdone;
|
||||
QString m_charsets;
|
||||
QString m_language;
|
||||
|
|
|
@ -810,7 +810,7 @@ int SlaveBase::waitForAnswer(int expected1, int expected2, QByteArray &data, int
|
|||
if (isSubCommand(cmd)) {
|
||||
dispatch(cmd, data);
|
||||
} else {
|
||||
kFatal(7019) << "Got cmd " << cmd << " while waiting for an answer!";
|
||||
kFatal(7019) << "Got cmd " << cmd << "while waiting for" << expected1 << expected2;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -866,8 +866,9 @@ void SlaveBase::dispatch(int command, const QByteArray &data)
|
|||
}
|
||||
case CMD_PUT: {
|
||||
KUrl url;
|
||||
int permissions;
|
||||
qint8 iOverwrite, iResume;
|
||||
int permissions = 0;
|
||||
qint8 iOverwrite = 0;
|
||||
qint8 iResume = 0;
|
||||
stream >> url >> iOverwrite >> iResume >> permissions;
|
||||
JobFlags flags = DefaultFlags;
|
||||
if (iOverwrite != 0) {
|
||||
|
@ -916,7 +917,7 @@ void SlaveBase::dispatch(int command, const QByteArray &data)
|
|||
}
|
||||
case CMD_MKDIR: {
|
||||
KUrl url;
|
||||
int i;
|
||||
int i = 0;
|
||||
stream >> url >> i;
|
||||
d->m_state = SlaveBasePrivate::InsideMethod;
|
||||
mkdir(url, i);
|
||||
|
@ -942,7 +943,7 @@ void SlaveBase::dispatch(int command, const QByteArray &data)
|
|||
case CMD_SYMLINK: {
|
||||
KUrl url;
|
||||
QString target;
|
||||
qint8 iOverwrite;
|
||||
qint8 iOverwrite = 0;
|
||||
stream >> target >> url >> iOverwrite;
|
||||
JobFlags flags = DefaultFlags;
|
||||
if (iOverwrite != 0) {
|
||||
|
@ -957,8 +958,8 @@ void SlaveBase::dispatch(int command, const QByteArray &data)
|
|||
case CMD_COPY: {
|
||||
KUrl url;
|
||||
KUrl url2;
|
||||
int permissions;
|
||||
qint8 iOverwrite;
|
||||
int permissions = 0;
|
||||
qint8 iOverwrite = 0;
|
||||
stream >> url >> url2 >> permissions >> iOverwrite;
|
||||
JobFlags flags = DefaultFlags;
|
||||
if (iOverwrite != 0) {
|
||||
|
@ -982,7 +983,7 @@ void SlaveBase::dispatch(int command, const QByteArray &data)
|
|||
}
|
||||
case CMD_CHMOD: {
|
||||
KUrl url;
|
||||
int i;
|
||||
int i = 0;
|
||||
stream >> url >> i;
|
||||
d->m_state = SlaveBasePrivate::InsideMethod;
|
||||
chmod(url, i);
|
||||
|
|
|
@ -447,7 +447,7 @@ void SlaveInterface::accept()
|
|||
void SlaveInterface::gotInput()
|
||||
{
|
||||
if (m_dead) {
|
||||
// already dead? then slaveDied was emitted and we are done
|
||||
// already dead? then slaveDied was emitted
|
||||
return;
|
||||
}
|
||||
ref();
|
||||
|
|
Loading…
Add table
Reference in a new issue