forked from qt-creator/qt-creator
ClangRefactoring: Add thread safety for progress report
Task-number: QTCREATORBUG-21950 Change-Id: Id067e23a501253f3b73671f6939164e314b5c8a9 Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -72,6 +72,48 @@ using ClangBackEnd::FilePathCache;
|
|||||||
using ClangBackEnd::FilePathView;
|
using ClangBackEnd::FilePathView;
|
||||||
using ClangBackEnd::TimeStamp;
|
using ClangBackEnd::TimeStamp;
|
||||||
|
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
|
||||||
|
template<typename CallableType>
|
||||||
|
class CallableEvent : public QEvent
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using Callable = std::decay_t<CallableType>;
|
||||||
|
CallableEvent(Callable &&callable)
|
||||||
|
: QEvent(QEvent::None)
|
||||||
|
, callable(std::move(callable))
|
||||||
|
{}
|
||||||
|
CallableEvent(const Callable &callable)
|
||||||
|
: QEvent(QEvent::None)
|
||||||
|
, callable(callable)
|
||||||
|
{}
|
||||||
|
|
||||||
|
~CallableEvent() { callable(); }
|
||||||
|
|
||||||
|
public:
|
||||||
|
Callable callable;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename Callable>
|
||||||
|
void executeInLoop(Callable &&callable, QObject *object = QCoreApplication::instance())
|
||||||
|
{
|
||||||
|
if (QThread *thread = qobject_cast<QThread *>(object))
|
||||||
|
object = QAbstractEventDispatcher::instance(thread);
|
||||||
|
|
||||||
|
QCoreApplication::postEvent(object,
|
||||||
|
new CallableEvent<Callable>(std::forward<Callable>(callable)),
|
||||||
|
Qt::HighEventPriority);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
template<typename Callable>
|
||||||
|
void executeInLoop(Callable &&callable, QObject *object = QCoreApplication::instance())
|
||||||
|
{
|
||||||
|
if (QThread *thread = qobject_cast<QThread *>(object))
|
||||||
|
object = QAbstractEventDispatcher::instance(thread);
|
||||||
|
|
||||||
|
QMetaObject::invokeMethod(object, std::forward<Callable>(callable));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
class PchManagerApplication final : public QCoreApplication
|
class PchManagerApplication final : public QCoreApplication
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -182,8 +224,9 @@ struct Data // because we have a cycle dependency
|
|||||||
clangPchManagerServer,
|
clangPchManagerServer,
|
||||||
includeWatcher};
|
includeWatcher};
|
||||||
PrecompiledHeaderStorage<> preCompiledHeaderStorage{database};
|
PrecompiledHeaderStorage<> preCompiledHeaderStorage{database};
|
||||||
ClangBackEnd::ProgressCounter progressCounter{
|
ClangBackEnd::ProgressCounter progressCounter{[&](int progress, int total) {
|
||||||
[&](int progress, int total) { clangPchManagerServer.setProgress(progress, total); }};
|
executeInLoop([&] { clangPchManagerServer.setProgress(progress, total); });
|
||||||
|
}};
|
||||||
ClangBackEnd::PchTaskQueue pchTaskQueue{systemTaskScheduler,
|
ClangBackEnd::PchTaskQueue pchTaskQueue{systemTaskScheduler,
|
||||||
projectTaskScheduler,
|
projectTaskScheduler,
|
||||||
progressCounter,
|
progressCounter,
|
||||||
|
Reference in New Issue
Block a user