From d3392418c458a2d9e02f3dcc83978e2f1e11e98b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Peter=20K=C3=BCmmel?= Date: Thu, 21 Oct 2010 21:29:08 +0000 Subject: [PATCH] use QWaitCondition instead of QEventLoop for waiting on GUI thread-call finished, it's cheaper git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35763 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/InGuiThread.cpp | 16 ++++++++-------- src/frontends/qt4/InGuiThread.h | 8 ++++++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/frontends/qt4/InGuiThread.cpp b/src/frontends/qt4/InGuiThread.cpp index b9332997f1..ff53f9d0e9 100644 --- a/src/frontends/qt4/InGuiThread.cpp +++ b/src/frontends/qt4/InGuiThread.cpp @@ -15,6 +15,8 @@ #include #include #include +#include + namespace lyx { namespace frontend { @@ -32,13 +34,11 @@ void IntoGuiThreadMover::callInGuiThread() synchronousFunctionCall(); } else { moveToThread(gui_thread); - connect(this, SIGNAL(triggerCall()), this, SLOT(doFunctionCall()), - Qt::QueuedConnection); - // TODO try with condition, it's maybe cheaper - QEventLoop loop; - connect(this, SIGNAL(called()), &loop, SLOT(quit())); - Q_EMIT triggerCall(); - loop.exec(); + connect(this, SIGNAL(triggerFunctionCall()), + this, SLOT(doFunctionCall()), Qt::QueuedConnection); + QMutexLocker lock(&sync_mutex_); + Q_EMIT triggerFunctionCall(); + condition_.wait(&sync_mutex_); } } @@ -46,7 +46,7 @@ void IntoGuiThreadMover::callInGuiThread() void IntoGuiThreadMover::doFunctionCall() { synchronousFunctionCall(); - Q_EMIT called(); + condition_.wakeOne(); } diff --git a/src/frontends/qt4/InGuiThread.h b/src/frontends/qt4/InGuiThread.h index 6d3b778a04..73a9d4ccd6 100644 --- a/src/frontends/qt4/InGuiThread.h +++ b/src/frontends/qt4/InGuiThread.h @@ -12,7 +12,9 @@ #ifndef INGUITHREAD_H #define INGUITHREAD_H +#include #include +#include #include "support/bind.h" #include "support/functional.h" @@ -32,14 +34,16 @@ protected: void callInGuiThread(); Q_SIGNALS: - void triggerCall(); - void called(); + void triggerFunctionCall(); private Q_SLOTS: void doFunctionCall(); private: virtual void synchronousFunctionCall() = 0; + + QWaitCondition condition_; + QMutex sync_mutex_; }; -- 2.39.2