forked from qt-creator/qt-creator
Make a reaper usable for processes from non-main thread
The reap() method needs to be called from the same thread as the passed process lives in. In case we are passing a process that lives in a non-main thread, we move it into the main thread and schedule a call to reap it again, this time from the main thread. In addition, make sure that Internal::d is accessed only from the main thread. Change-Id: I32c836584b5da3050f9254e53cee352c79e536b9 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -157,6 +157,19 @@ void reap(QtcProcess *process, int timeoutMs)
|
|||||||
if (!process)
|
if (!process)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
QTC_ASSERT(QThread::currentThread() == process->thread(), return);
|
||||||
|
|
||||||
|
// Neither can move object with a parent into a different thread
|
||||||
|
// nor reaping the process with a parent makes any sense.
|
||||||
|
process->setParent(nullptr);
|
||||||
|
if (process->thread() != qApp->thread()) {
|
||||||
|
process->moveToThread(qApp->thread());
|
||||||
|
QMetaObject::invokeMethod(process, [process, timeoutMs] {
|
||||||
|
reap(process, timeoutMs);
|
||||||
|
}); // will be queued
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QTC_ASSERT(Internal::d, return);
|
QTC_ASSERT(Internal::d, return);
|
||||||
|
|
||||||
new Internal::ProcessReaper(process, timeoutMs);
|
new Internal::ProcessReaper(process, timeoutMs);
|
||||||
|
Reference in New Issue
Block a user