Clang: Share executeInLoop

Change-Id: Id02902e1e7abdb8b3430e7b228547c4372a424ce
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Marco Bubke
2019-02-22 11:37:30 +01:00
parent 3824fcbe28
commit 211aef94e6
5 changed files with 76 additions and 125 deletions

View File

@@ -108,6 +108,7 @@ HEADERS += \
$$PWD/clangrefactoringservermessages.h \
$$PWD/alivemessage.h \
$$PWD/completionsmessage.h \
$$PWD/executeinloop.h \
$$PWD/requestcompletionsmessage.h \
$$PWD/echomessage.h \
$$PWD/endmessage.h \

View 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

View File

@@ -29,6 +29,7 @@
#include <clangpathwatcher.h>
#include <connectionserver.h>
#include <environment.h>
#include <executeinloop.h>
#include <generatedfiles.h>
#include <modifiedtimechecker.h>
#include <pchcreator.h>
@@ -72,48 +73,6 @@ using ClangBackEnd::FilePathCache;
using ClangBackEnd::FilePathView;
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
{
public:

View File

@@ -30,6 +30,7 @@
#include "queueinterface.h"
#include "progresscounter.h"
#include <executeinloop.h>
#include <processormanagerinterface.h>
#include <symbolindexertaskqueueinterface.h>
#include <symbolscollectorinterface.h>
@@ -149,47 +150,6 @@ private:
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:
std::vector<Future> m_futures;
ProcessorManager &m_processorManager;

View File

@@ -30,6 +30,7 @@
#include <QDir>
#include <connectionserver.h>
#include <executeinloop.h>
#include <filepathcaching.h>
#include <generatedfiles.h>
#include <refactoringserver.h>
@@ -51,48 +52,6 @@ using ClangBackEnd::RefactoringDatabaseInitializer;
using ClangBackEnd::ConnectionServer;
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)
{
QCommandLineParser parser;