[Telepathy-commits] [telepathy-qt4/master] Only hold the handleContext mutex as long as you really need it in requestHandles and referenceHandles

Olli Salli olli.salli at collabora.co.uk
Wed Jan 21 04:42:19 PST 2009


---
 TelepathyQt4/cli-connection.cpp |   31 +++++++++++++++++++------------
 1 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/TelepathyQt4/cli-connection.cpp b/TelepathyQt4/cli-connection.cpp
index db96de5..fd71454 100644
--- a/TelepathyQt4/cli-connection.cpp
+++ b/TelepathyQt4/cli-connection.cpp
@@ -592,12 +592,14 @@ PendingOperation* Connection::requestConnect()
 
 PendingHandles* Connection::requestHandles(uint handleType, const QStringList& names)
 {
-    Private::HandleContext *handleContext = mPriv->handleContext;
-    QMutexLocker locker(&handleContext->lock);
-    handleContext->types[handleType].requestsInFlight++;
-
     debug() << "Request for" << names.length() << "handles of type" << handleType;
 
+    {
+        Private::HandleContext *handleContext = mPriv->handleContext;
+        QMutexLocker locker(&handleContext->lock);
+        handleContext->types[handleType].requestsInFlight++;
+    }
+
     PendingHandles* pending =
         new PendingHandles(this, handleType, names);
     QDBusPendingCallWatcher* watcher =
@@ -611,19 +613,24 @@ PendingHandles* Connection::requestHandles(uint handleType, const QStringList& n
 
 PendingHandles* Connection::referenceHandles(uint handleType, const UIntList& handles)
 {
-    Private::HandleContext *handleContext = mPriv->handleContext;
-    QMutexLocker locker(&handleContext->lock);
-
     debug() << "Reference of" << handles.length() << "handles of type" << handleType;
 
     UIntList alreadyHeld;
     UIntList notYetHeld;
-    foreach (uint handle, handles) {
-        if (handleContext->types[handleType].refcounts.contains(handle) || handleContext->types[handleType].toRelease.contains(handle))
-            alreadyHeld.push_back(handle);
-        else
-            notYetHeld.push_back(handle);
+    {
+        Private::HandleContext *handleContext = mPriv->handleContext;
+        QMutexLocker locker(&handleContext->lock);
+
+        foreach (uint handle, handles) {
+            if (handleContext->types[handleType].refcounts.contains(handle)
+                    || handleContext->types[handleType].toRelease.contains(handle)) {
+                alreadyHeld.push_back(handle);
+            } else {
+                notYetHeld.push_back(handle);
+            }
+        }
     }
+
     debug() << " Already holding" << alreadyHeld.size() << "of the handles -" << notYetHeld.size() << "to go";
 
     PendingHandles* pending =
-- 
1.5.6.5




More information about the Telepathy-commits mailing list