]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/InGuiThread.cpp
use QWaitCondition instead of QEventLoop for waiting on GUI thread-call finished...
[lyx.git] / src / frontends / qt4 / InGuiThread.cpp
1 /**
2  * \file InGuiThread.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Peter Kümmel
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InGuiThread.h"
14
15 #include <QThread>
16 #include <QEventLoop>
17 #include <QApplication>
18 #include <QMutexLocker>
19
20
21 namespace lyx {
22 namespace frontend {
23
24
25 IntoGuiThreadMover::IntoGuiThreadMover()
26 {
27 }
28
29
30 void IntoGuiThreadMover::callInGuiThread()
31 {
32         QThread* gui_thread = QApplication::instance()->thread();
33         if (QThread::currentThread() == gui_thread) {
34                 synchronousFunctionCall();
35         } else {
36                 moveToThread(gui_thread);
37                 connect(this, SIGNAL(triggerFunctionCall()), 
38                         this, SLOT(doFunctionCall()), Qt::QueuedConnection);
39                 QMutexLocker lock(&sync_mutex_);
40                 Q_EMIT triggerFunctionCall();
41                 condition_.wait(&sync_mutex_);
42         }
43 }
44
45
46 void IntoGuiThreadMover::doFunctionCall()
47 {
48         synchronousFunctionCall();
49         condition_.wakeOne();
50 }
51
52
53 } // namespace frontend
54 } // namespace lyx
55
56 #include "moc_InGuiThread.cpp"