Happy new year 2020!
[simple-x264-launcher.git] / src / thread_abstract.cpp
blobaea79d03d8a76f3b8c7953b4124edc47b8d2c765
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2020 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "thread_abstract.h"
24 //MUtils
25 #include <MUtils/Global.h>
27 //Qt
28 #include <QDir>
29 #include <QElapsedTimer>
30 #include <QProcess>
32 //-------------------------------------
33 // Constructor
34 //-------------------------------------
36 AbstractThread::AbstractThread(void)
38 m_exception = false;
39 m_success = 0;
42 AbstractThread::~AbstractThread(void)
46 //-------------------------------------
47 // Thread entry point
48 //-------------------------------------
50 void AbstractThread::run(void)
52 m_exception = false;
53 m_success = 0;
54 runChecked1(this, m_success, &m_exception);
57 void AbstractThread::runChecked1(AbstractThread *const thread, volatile int &success, volatile bool *exception)
59 #if !defined(_DEBUG)
60 __try
62 return runChecked2(thread, success, exception);
64 __except(1)
66 *exception = true;
67 qWarning("Unhandled structured exception in worker thread !!!");
69 #else
70 return runChecked2(thread, success, exception);
71 #endif
74 void AbstractThread::runChecked2(AbstractThread *const thread, volatile int &success, volatile bool *exception)
76 #if !defined(_DEBUG)
77 try
79 success = thread->threadMain();
81 catch(const std::exception &e)
83 *exception = true;
84 qWarning("Worker thread raised an C++ exception: %s", e.what());
86 catch(char *const msg)
88 *exception = true;
89 qWarning("Worker thread raised an C++ exception: %s", msg);
91 catch(...)
93 *exception = true;
94 qWarning("Worker thread raised an C++ exception!");
96 #else
97 success = thread->threadMain();
98 #endif