SVN commit 1214926 by aseigo:

QString is not thread-safe; since the matches get shuttled around between 
threads, we need to protect access to it. as writing is rare, this should 
hopefully not degrade performance too much. if it passes testing, then i will 
backport this.
CCBUG:238556
CCMAIL:plasma-devel@kde.org


 M  +37 -0     querymatch.cpp  


--- trunk/KDE/kdelibs/plasma/querymatch.cpp #1214925:1214926
@@ -21,6 +21,7 @@
 
 #include <QAction>
 #include <QIcon>
+#include <QReadWriteLock>
 #include <QSharedData>
 #include <QStringList>
 #include <QVariant>
@@ -38,6 +39,7 @@
     public:
         QueryMatchPrivate(AbstractRunner *r)
             : QSharedData(),
+              lock(new QReadWriteLock(QReadWriteLock::Recursive)),
               runner(r),
               type(QueryMatch::ExactMatch),
               relevance(.7),
@@ -47,6 +49,30 @@
         {
         }
 
+        QueryMatchPrivate(const QueryMatchPrivate &other)
+            : QSharedData(other),
+              lock(new QReadWriteLock(QReadWriteLock::Recursive))
+        {
+            QReadLocker lock(other.lock);
+            runner = other.runner;
+            type = other.type;
+            relevance = other.relevance;
+            selAction = other.selAction;
+            enabled = other.enabled;
+            idSetByData = other.idSetByData;
+            id = other.id;
+            text = other.text;
+            subtext = other.subtext;
+            icon = other.icon;
+            data = other.data;
+        }
+
+        ~QueryMatchPrivate()
+        {
+            delete lock;
+        }
+
+        QReadWriteLock *lock;
         QWeakPointer<AbstractRunner> runner;
         QueryMatch::Type type;
         QString id;
@@ -116,16 +142,19 @@
 
 void QueryMatch::setText(const QString &text)
 {
+    QWriteLocker locker(d->lock);
     d->text = text;
 }
 
 void QueryMatch::setSubtext(const QString &subtext)
 {
+    QWriteLocker locker(d->lock);
     d->subtext = subtext;
 }
 
 void QueryMatch::setData(const QVariant & data)
 {
+    QWriteLocker locker(d->lock);
     d->data = data;
 
     if (d->id.isEmpty() || d->idSetByData) {
@@ -139,6 +168,7 @@
 
 void QueryMatch::setId(const QString &id)
 {
+    QWriteLocker locker(d->lock);
     if (d->runner) {
         d->id = d->runner.data()->id();
     }
@@ -152,26 +182,31 @@
 
 void QueryMatch::setIcon(const QIcon &icon)
 {
+    QWriteLocker locker(d->lock);
     d->icon = icon;
 }
 
 QVariant QueryMatch::data() const
 {
+    QReadLocker locker(d->lock);
     return d->data;
 }
 
 QString QueryMatch::text() const
 {
+    QReadLocker locker(d->lock);
     return d->text;
 }
 
 QString QueryMatch::subtext() const
 {
+    QReadLocker locker(d->lock);
     return d->subtext;
 }
 
 QIcon QueryMatch::icon() const
 {
+    QReadLocker locker(d->lock);
     return d->icon;
 }
 
@@ -206,6 +241,8 @@
             return d->relevance < other.d->relevance;
         }
 
+        QReadLocker locker(d->lock);
+        QReadLocker otherLocker(other.d->lock);
         // when resorting to sort by alpha, we want the
         // reverse sort order!
         return d->text > other.d->text;
_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel

Reply via email to