#include <QThread>
#include <QEventLoop>
#include <QApplication>
+#include <QMutexLocker>
+
namespace lyx {
namespace frontend {
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_);
}
}
void IntoGuiThreadMover::doFunctionCall()
{
synchronousFunctionCall();
- Q_EMIT called();
+ condition_.wakeOne();
}
#ifndef INGUITHREAD_H
#define INGUITHREAD_H
+#include <QMutex>
#include <QObject>
+#include <QWaitCondition>
#include "support/bind.h"
#include "support/functional.h"
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_;
};