forked from qt-creator/qt-creator
Clang: Share executeInLoop
Change-Id: Id02902e1e7abdb8b3430e7b228547c4372a424ce Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -108,6 +108,7 @@ HEADERS += \
|
|||||||
$$PWD/clangrefactoringservermessages.h \
|
$$PWD/clangrefactoringservermessages.h \
|
||||||
$$PWD/alivemessage.h \
|
$$PWD/alivemessage.h \
|
||||||
$$PWD/completionsmessage.h \
|
$$PWD/completionsmessage.h \
|
||||||
|
$$PWD/executeinloop.h \
|
||||||
$$PWD/requestcompletionsmessage.h \
|
$$PWD/requestcompletionsmessage.h \
|
||||||
$$PWD/echomessage.h \
|
$$PWD/echomessage.h \
|
||||||
$$PWD/endmessage.h \
|
$$PWD/endmessage.h \
|
||||||
|
72
src/libs/clangsupport/executeinloop.h
Normal file
72
src/libs/clangsupport/executeinloop.h
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2018 The Qt Company Ltd.
|
||||||
|
** Contact: https://www.qt.io/licensing/
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator.
|
||||||
|
**
|
||||||
|
** Commercial License Usage
|
||||||
|
** Licensees holding valid commercial Qt licenses may use this file in
|
||||||
|
** accordance with the commercial license agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and The Qt Company. For licensing terms
|
||||||
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||||
|
** information use the contact form at https://www.qt.io/contact-us.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3 as published by the Free Software
|
||||||
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||||
|
** included in the packaging of this file. Please review the following
|
||||||
|
** information to ensure the GNU General Public License requirements will
|
||||||
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QAbstractEventDispatcher>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QThread>
|
||||||
|
|
||||||
|
#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
|
@@ -29,6 +29,7 @@
|
|||||||
#include <clangpathwatcher.h>
|
#include <clangpathwatcher.h>
|
||||||
#include <connectionserver.h>
|
#include <connectionserver.h>
|
||||||
#include <environment.h>
|
#include <environment.h>
|
||||||
|
#include <executeinloop.h>
|
||||||
#include <generatedfiles.h>
|
#include <generatedfiles.h>
|
||||||
#include <modifiedtimechecker.h>
|
#include <modifiedtimechecker.h>
|
||||||
#include <pchcreator.h>
|
#include <pchcreator.h>
|
||||||
@@ -72,48 +73,6 @@ 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:
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
#include "queueinterface.h"
|
#include "queueinterface.h"
|
||||||
#include "progresscounter.h"
|
#include "progresscounter.h"
|
||||||
|
|
||||||
|
#include <executeinloop.h>
|
||||||
#include <processormanagerinterface.h>
|
#include <processormanagerinterface.h>
|
||||||
#include <symbolindexertaskqueueinterface.h>
|
#include <symbolindexertaskqueueinterface.h>
|
||||||
#include <symbolscollectorinterface.h>
|
#include <symbolscollectorinterface.h>
|
||||||
@@ -149,47 +150,6 @@ private:
|
|||||||
m_futures.erase(split, m_futures.end());
|
m_futures.erase(split, m_futures.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
#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
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Future> m_futures;
|
std::vector<Future> m_futures;
|
||||||
ProcessorManager &m_processorManager;
|
ProcessorManager &m_processorManager;
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
#include <connectionserver.h>
|
#include <connectionserver.h>
|
||||||
|
#include <executeinloop.h>
|
||||||
#include <filepathcaching.h>
|
#include <filepathcaching.h>
|
||||||
#include <generatedfiles.h>
|
#include <generatedfiles.h>
|
||||||
#include <refactoringserver.h>
|
#include <refactoringserver.h>
|
||||||
@@ -51,48 +52,6 @@ using ClangBackEnd::RefactoringDatabaseInitializer;
|
|||||||
using ClangBackEnd::ConnectionServer;
|
using ClangBackEnd::ConnectionServer;
|
||||||
using ClangBackEnd::SymbolIndexing;
|
using ClangBackEnd::SymbolIndexing;
|
||||||
|
|
||||||
#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
|
|
||||||
|
|
||||||
QStringList processArguments(QCoreApplication &application)
|
QStringList processArguments(QCoreApplication &application)
|
||||||
{
|
{
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
|
Reference in New Issue
Block a user