some light weight locking around the speed member

svn path=/trunk/KDE/kdelibs/; revision=1032959
This commit is contained in:
Aaron J. Seigo 2009-10-08 23:32:25 +00:00
parent fad3e0814b
commit d8d346822e

View File

@ -24,6 +24,7 @@
#include <QMenu> #include <QMenu>
#include <QMutex> #include <QMutex>
#include <QMutexLocker> #include <QMutexLocker>
#include <QReadWriteLock>
#include <QTimer> #include <QTimer>
#include <kdebug.h> #include <kdebug.h>
@ -98,6 +99,7 @@ public:
QHash<QString, QAction*> actions; QHash<QString, QAction*> actions;
QList<RunnerSyntax> syntaxes; QList<RunnerSyntax> syntaxes;
bool hasRunOptions; bool hasRunOptions;
QReadWriteLock speedLock;
}; };
K_GLOBAL_STATIC(QMutex, s_bigLock) K_GLOBAL_STATIC(QMutex, s_bigLock)
@ -242,12 +244,18 @@ void AbstractRunner::createRunOptions(QWidget *parent)
AbstractRunner::Speed AbstractRunner::speed() const AbstractRunner::Speed AbstractRunner::speed() const
{ {
return d->speed; // the only time the read lock will fail is if we were slow are going to speed up
// or if we were fast and are going to slow down; so don't wait in this case, just
// say we're slow. we either will be soon or were just a moment ago and it doesn't
// hurt to do one more run the slow way
return d->speedLock.tryLockForRead() ? d->speed : SlowSpeed;
} }
void AbstractRunner::setSpeed(Speed speed) void AbstractRunner::setSpeed(Speed speed)
{ {
d->speedLock.lockForWrite();
d->speed = speed; d->speed = speed;
d->speedLock.unlock();
} }
AbstractRunner::Priority AbstractRunner::priority() const AbstractRunner::Priority AbstractRunner::priority() const