#include "InGuiThread.h"
+#include "frontends/Application.h"
+
#include <QThread>
#include <QEventLoop>
#include <QApplication>
+#include <QMutexLocker>
+
namespace lyx {
namespace frontend {
IntoGuiThreadMover::IntoGuiThreadMover()
{
- moveToThread(QApplication::instance()->thread());
- connect(this, SIGNAL(triggerCall()), this, SLOT(doFunctionCall()),
- Qt::QueuedConnection);
}
void IntoGuiThreadMover::callInGuiThread()
{
- if (QThread::currentThread() == QApplication::instance()->thread()) {
+ if (!theApp() || !QApplication::instance() ||
+ QThread::currentThread() == QApplication::instance()->thread()) {
synchronousFunctionCall();
} else {
- QEventLoop loop;
- connect(this, SIGNAL(called()), &loop, SLOT(quit()));
- Q_EMIT triggerCall();
- loop.exec();
+ moveToThread(QApplication::instance()->thread());
+ connect(this, SIGNAL(triggerFunctionCall()),
+ this, SLOT(doFunctionCall()), Qt::QueuedConnection);
+ QMutexLocker lock(&sync_mutex_);
+ Q_EMIT triggerFunctionCall();
+ condition_.wait(&sync_mutex_);
}
}
void IntoGuiThreadMover::doFunctionCall()
{
synchronousFunctionCall();
- Q_EMIT called();
+ condition_.wakeOne();
}