]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix crashing on starting and quitting
authorMartin T. H. Sandsmark <martin.sandsmark@kde.org>
Tue, 7 Apr 2020 15:14:59 +0000 (17:14 +0200)
committerMartin T. H. Sandsmark <martin.sandsmark@kde.org>
Sun, 12 Apr 2020 10:15:03 +0000 (12:15 +0200)
QCollator (especially with Qt 5.14 and ICU 65.1) is very unhappy with
threads.

To avoid having to lock and unlock the mutex everywhere (and ensure it
is unlocked before calling other things that might lock it, etc.), we do
it as locally as possible. Even if for some reason Qt and ICU make
QCollator threadsafe in the future locking here should have minimal
impact.

BUG: 419585

Differential Revision: https://phabricator.kde.org/D28659

src/kitemviews/kfileitemmodel.cpp

index 4b35a0248a5e07f976451fc2b5f80792bc64d5d5..e4dca2734871d3b0c9e0dc0da1375fab76d202e5 100644 (file)
@@ -33,6 +33,9 @@
 #include <QMimeData>
 #include <QTimer>
 #include <QWidget>
+#include <QMutex>
+
+Q_GLOBAL_STATIC_WITH_ARGS(QMutex, s_collatorMutex, (QMutex::Recursive))
 
 // #define KFILEITEMMODEL_DEBUG
 
@@ -1878,6 +1881,8 @@ int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b, const
 
 int KFileItemModel::stringCompare(const QString& a, const QString& b, const QCollator& collator) const
 {
+    QMutexLocker collatorLock(s_collatorMutex());
+
     if (m_naturalSorting) {
         return collator.compare(a, b);
     }