diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2009-06-03 09:23:33 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2009-06-03 09:23:33 (GMT) |
commit | ee735a39a333ddff4d5d0734062093ba553850f2 (patch) | |
tree | 7801cfb85082a52990314398b2569cc25e5370ce /src | |
parent | e11ff338951954f08866aef15607e8fae2bc150c (diff) | |
download | Qt-ee735a39a333ddff4d5d0734062093ba553850f2.zip Qt-ee735a39a333ddff4d5d0734062093ba553850f2.tar.gz Qt-ee735a39a333ddff4d5d0734062093ba553850f2.tar.bz2 |
use of QMutexPool to reduce the number of Q_GLOBAL_STATIC in the
animation framework
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/animation/qpropertyanimation.cpp | 47 | ||||
-rw-r--r-- | src/corelib/animation/qvariantanimation.cpp | 29 |
2 files changed, 40 insertions, 36 deletions
diff --git a/src/corelib/animation/qpropertyanimation.cpp b/src/corelib/animation/qpropertyanimation.cpp index 43b5283..357a6ac 100644 --- a/src/corelib/animation/qpropertyanimation.cpp +++ b/src/corelib/animation/qpropertyanimation.cpp @@ -91,19 +91,17 @@ #include "qpropertyanimation.h" #include "qanimationgroup.h" -#include <QtCore/qdebug.h> - #include "qpropertyanimation_p.h" #include <QtCore/qmath.h> #include <QtCore/qmutex.h> +#include <private/qmutexpool_p.h> QT_BEGIN_NAMESPACE typedef QPair<QObject *, QByteArray> QPropertyAnimationPair; typedef QHash<QPropertyAnimationPair, QPropertyAnimation*> QPropertyAnimationHash; Q_GLOBAL_STATIC(QPropertyAnimationHash, _q_runningAnimations) -Q_GLOBAL_STATIC_WITH_ARGS(QMutex, guardHashLock, (QMutex::Recursive) ) void QPropertyAnimationPrivate::updateMetaProperty() { @@ -284,27 +282,32 @@ void QPropertyAnimation::updateState(QAbstractAnimation::State oldState, } QVariantAnimation::updateState(oldState, newState); - QMutexLocker locker(guardHashLock()); - QPropertyAnimationHash * hash = _q_runningAnimations(); - QPropertyAnimationPair key(d->target, d->propertyName); - if (newState == Running) { - d->updateMetaProperty(); - QPropertyAnimation *oldAnim = hash->value(key, 0); - if (oldAnim) { - // try to stop the top level group - QAbstractAnimation *current = oldAnim; - while (current->group() && current->state() != Stopped) - current = current->group(); - current->stop(); - } - hash->insert(key, this); - // update the default start value - if (oldState == Stopped) { - d->setDefaultStartValue(d->target->property(d->propertyName.constData())); + QPropertyAnimation *animToStop = 0; + { + QPropertyAnimationHash * hash = _q_runningAnimations(); + QMutexLocker locker(QMutexPool::globalInstanceGet(hash)); + QPropertyAnimationPair key(d->target, d->propertyName); + if (newState == Running) { + d->updateMetaProperty(); + animToStop = hash->value(key, 0); + hash->insert(key, this); + // update the default start value + if (oldState == Stopped) { + d->setDefaultStartValue(d->target->property(d->propertyName.constData())); + } + } else if (hash->value(key) == this) { + hash->remove(key); } - } else if (hash->value(key) == this) { - hash->remove(key); + } + + //we need to do that after the mutex was unlocked + if (animToStop) { + // try to stop the top level group + QAbstractAnimation *current = animToStop; + while (current->group() && current->state() != Stopped) + current = current->group(); + current->stop(); } } diff --git a/src/corelib/animation/qvariantanimation.cpp b/src/corelib/animation/qvariantanimation.cpp index e973ec5..a3fa93a 100644 --- a/src/corelib/animation/qvariantanimation.cpp +++ b/src/corelib/animation/qvariantanimation.cpp @@ -44,11 +44,10 @@ #include "qvariantanimation.h" #include "qvariantanimation_p.h" -#include <QtCore/QRect> -#include <QtCore/QLineF> -#include <QtCore/QLine> -#include <QtCore/QReadWriteLock> -#include <QtCore/qdebug.h> +#include <QtCore/qrect.h> +#include <QtCore/qline.h> +#include <QtCore/qmutex.h> +#include <private/qmutexpool_p.h> QT_BEGIN_NAMESPACE @@ -365,8 +364,8 @@ void QVariantAnimation::setEasingCurve(const QEasingCurve &easing) d->recalculateCurrentInterval(); } -Q_GLOBAL_STATIC(QVector<QVariantAnimation::Interpolator>, registeredInterpolators) -Q_GLOBAL_STATIC(QReadWriteLock, registeredInterpolatorsLock) +typedef QVector<QVariantAnimation::Interpolator> QInterpolatorVector; +Q_GLOBAL_STATIC(QInterpolatorVector, registeredInterpolators) /*! \fn void qRegisterAnimationInterpolator(QVariant (*func)(const T &from, const T &to, qreal progress)) @@ -398,10 +397,11 @@ Q_GLOBAL_STATIC(QReadWriteLock, registeredInterpolatorsLock) void QVariantAnimation::registerInterpolator(QVariantAnimation::Interpolator func, int interpolationType) { // will override any existing interpolators - QWriteLocker locker(registeredInterpolatorsLock()); - if (int(interpolationType) >= registeredInterpolators()->count()) - registeredInterpolators()->resize(int(interpolationType) + 1); - registeredInterpolators()->replace(interpolationType, func); + QInterpolatorVector *interpolators = registeredInterpolators(); + QMutexLocker locker(QMutexPool::globalInstanceGet(interpolators)); + if (int(interpolationType) >= interpolators->count()) + interpolators->resize(int(interpolationType) + 1); + interpolators->replace(interpolationType, func); } @@ -412,10 +412,11 @@ template<typename T> static inline QVariantAnimation::Interpolator castToInterpo QVariantAnimation::Interpolator QVariantAnimationPrivate::getInterpolator(int interpolationType) { - QReadLocker locker(registeredInterpolatorsLock()); + QInterpolatorVector *interpolators = registeredInterpolators(); + QMutexLocker locker(QMutexPool::globalInstanceGet(interpolators)); QVariantAnimation::Interpolator ret = 0; - if (interpolationType < registeredInterpolators()->count()) { - ret = registeredInterpolators()->at(interpolationType); + if (interpolationType < interpolators->count()) { + ret = interpolators->at(interpolationType); if (ret) return ret; } |