1 /**
2 * UGENE - Integrated Bioinformatics Tools.
3 * Copyright (C) 2008-2017 UniPro <ugene@unipro.ru>
4 * http://ugene.net
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 * MA 02110-1301, USA.
20 */
21
22 #include <core/MainThreadRunnable.h>
23
24 #include "GTGlobals.h"
25 #include "core/MainThreadTimer.h"
26 #include "utils/GTThread.h"
27
28 namespace HI {
29
30 #define GT_CLASS_NAME "ThreadWaiter"
31 const qint64 TIMER_INTERVAL = 100;
32
ThreadWaiter()33 ThreadWaiter::ThreadWaiter()
34 : // os(os),
35 startValue(0),
36 endValue(0) {
37 }
38
39 #define GT_METHOD_NAME "wait"
wait()40 void ThreadWaiter::wait() {
41 MainThreadTimer mainThreadTimer(TIMER_INTERVAL);
42 startValue = mainThreadTimer.getCounter();
43 while (endValue <= startValue) {
44 GTGlobals::sleep(TIMER_INTERVAL);
45 endValue = mainThreadTimer.getCounter();
46 }
47 }
48 #undef GT_METHOD_NAME
49
50 #undef GT_CLASS_NAME
51
52 #define GT_CLASS_NAME "GTThread"
53
54 #define GT_METHOD_NAME "waitForMainThread"
waitForMainThread()55 void GTThread::waitForMainThread() {
56 ThreadWaiter waiter;
57 waiter.wait();
58 }
59 #undef GT_METHOD_NAME
60
61 #define GT_METHOD_NAME "runInMainThread"
runInMainThread(GUITestOpStatus & os,CustomScenario * scenario)62 void GTThread::runInMainThread(GUITestOpStatus &os, CustomScenario *scenario) {
63 qDebug("Running in the main thread");
64 MainThreadRunnable::runInMainThread(os, scenario);
65 qDebug("Run in the main thread is finished");
66 }
67 #undef GT_METHOD_NAME
68
69 #undef GT_CLASS_NAME
70
71 } // namespace HI
72