Git commit d78f4ad88a2f82e1d17491b83bb806c93908d464 by Ivan =C4=8Cuki=C4=87. Committed on 29/09/2012 at 10:26. Pushed by ivan into branch 'master'. Made caching threadsafe so that kwin doesn't break M +1 -0 .gitignore M +4 -3 src/lib/consumer.cpp M +17 -6 src/lib/utils_p.h http://commits.kde.org/kactivities/d78f4ad88a2f82e1d17491b83bb806c93908d464 diff --git a/.gitignore b/.gitignore index d4d6f64..f670441 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ _tests *swp *~ .kdev4 +.cmake-params kactivities.kdev4 diff --git a/src/lib/consumer.cpp b/src/lib/consumer.cpp index 3c0090b..e6c8d77 100644 --- a/src/lib/consumer.cpp +++ b/src/lib/consumer.cpp @@ -69,6 +69,9 @@ ConsumerPrivate::ConsumerPrivate() connect(Manager::self(), SIGNAL(servicePresenceChanged(bool)), this, SLOT(setServicePresent(bool))); = + kDebug() << "We are checking whether the service is present" << + Manager::isServicePresent(); + if (Manager::isServicePresent()) { initializeCachedData(); } @@ -131,8 +134,6 @@ void ConsumerPrivate::setActivityState(const QString & = activity, int state) } } = - - Consumer::Consumer(QObject * parent) : QObject(parent), d(ConsumerPrivate::self(this)) { @@ -160,7 +161,7 @@ QStringList Consumer::listActivities(Info::State state)= const if (state =3D=3D Info::Running) { if (!Manager::isServicePresent()) return QStringList(nulluuid); = - waitForCallFinished(d->runningActivitiesCallWatcher); + waitForCallFinished(d->runningActivitiesCallWatcher, &d->runningAc= tivitiesMutex); = kDebug() << "Returning the running activities" << d->runningActivi= ties; = diff --git a/src/lib/utils_p.h b/src/lib/utils_p.h index a57c638..f503a04 100644 --- a/src/lib/utils_p.h +++ b/src/lib/utils_p.h @@ -19,15 +19,19 @@ = #include = +#include + #include #include = // Creates an async call to retrieve a value from the dbus service // and initializes the call watcher #define KAMD_RETRIEVE_REMOTE_VALUE(Variable, MethodToCall, Target) = \ + kDebug() << "Locking mutex for" << #Variable; = \ + Variable##Mutex.lock(); = \ const QDBusPendingCall & Variable##Call =3D Manager::activities()->Met= hodToCall; \ - Variable##CallWatcher =3D new QDBusPendingCallWatcher(Variable##Call, = Target); \ - = \ + Variable##CallWatcher =3D new QDBusPendingCallWatcher(Variable##Call, = Target); \ + = \ QObject::connect(Variable##CallWatcher, SIGNAL(finished(QDBusPendingCa= llWatcher*)), \ Target, SLOT(Variable##CallFinished(QDBusPendingCallWatcher*))) = @@ -35,7 +39,8 @@ // without a handler for when a call is finished #define KAMD_REMOTE_VALUE_CUSTOM_HANDLER(Type, Name) \ mutable Type Name; \ - QDBusPendingCallWatcher * Name##CallWatcher + QDBusPendingCallWatcher * Name##CallWatcher; \ + QMutex Name##Mutex = // Defines a variable and handlers for a variable on a dbus service #define KAMD_REMOTE_VALUE(Type, Name) \ @@ -61,7 +66,7 @@ = // Defines a handler for pre-fetching of the activity info #define KAMD_RETRIEVE_REMOTE_VALUE_HANDLER(ReturnType, Namespace, Variable= , DefaultValue) \ - void Namespace::Variable##CallFinished(QDBusPendingCallWatcher * call)= \ + void Namespace::Variable##CallFinished(QDBusPendingCallWatcher * call)= \ { = \ QDBusPendingReply reply =3D * call; = \ = \ @@ -70,7 +75,9 @@ : reply.argumentAt<0>(); = \ = \ Variable##CallWatcher =3D 0; = \ + Variable##Mutex.unlock(); = \ call->deleteLater(); = \ + kDebug() << "Unlocked mutex"; = \ } = // Implements a value getter @@ -78,14 +85,18 @@ ReturnType Namespace::Variable() const \ { \ if (!Manager::isServicePresent()) return Default; \ - waitForCallFinished(d->Variable##CallWatcher); \ + waitForCallFinished(d->Variable##CallWatcher, &d->Variable##Mutex)= ; \ kDebug() << "Returning" << #Variable << d->Variable; \ return d->Variable; \ } = -static inline void waitForCallFinished(QDBusPendingCallWatcher * watcher) +static inline void waitForCallFinished(QDBusPendingCallWatcher * watcher, = QMutex * mutex) { if (watcher) { watcher->waitForFinished(); + + kDebug() << "Trying to lock mutex"; + mutex->lock(); + mutex->unlock(); } }