summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Vrátil <dvratil@kde.org>2016-10-13 19:35:46 (GMT)
committerDaniel Vrátil <dvratil@kde.org>2016-10-13 19:35:46 (GMT)
commite61d2d03e9fc9d8d353c6906984cf7c6b1f4f2ea (patch)
tree7a01cfcecb5c41d44de5759a9252dd7ce550cb88
parent88eeb24aaa9757f680f332e6895337adeb00f7b7 (diff)
Fix crash when Scotland is in the wrong thread
-rw-r--r--src/core/braveheart.cpp38
1 files changed, 25 insertions, 13 deletions
diff --git a/src/core/braveheart.cpp b/src/core/braveheart.cpp
index c455317..70b1d74 100644
--- a/src/core/braveheart.cpp
+++ b/src/core/braveheart.cpp
@@ -33,24 +33,36 @@ namespace Akonadi
class Braveheart
{
+private:
+ static void sonOfScotland()
+ {
+ Q_ASSERT(qApp->thread() == QThread::currentThread());
+
+ if (!qApp->property("__Akonadi__Braveheart").isNull()) {
+ // One Scottish warrior is enough....
+ return;
+ }
+ auto freedom = new QTimer(qApp);
+ QObject::connect(freedom, &QTimer::timeout,
+ freedom, []() {
+ // They may take our lives, but they will never
+ // take our memory!
+ malloc_trim(50 * 1024 * 1024);
+ });
+ // Fight for freedom every 15 minutes
+ freedom->start(15 * 60 * 1000);
+ qApp->setProperty("__Akonadi__Braveheart", true);
+ };
+
public:
explicit Braveheart()
{
qAddPreRoutine([]() {
- if (!qApp->property("__Akonadi__Braveheart").isNull()) {
- // One Scottish warrior is enough....
- return;
+ if (qApp->thread() != QThread::currentThread()) {
+ QTimer::singleShot(0, qApp, sonOfScotland);
+ } else {
+ sonOfScotland();
}
- auto freedom = new QTimer();
- QObject::connect(freedom, &QTimer::timeout,
- freedom, []() {
- // They may take our lives, but they will never
- // take our memory!
- malloc_trim(50 * 1024 * 1024);
- });
- // Fight for freedom every 15 minutes
- freedom->start(15 * 60 * 1000);
- qApp->setProperty("__Akonadi__Braveheart", true);
});
}
};