forked from qt-creator/qt-creator
RunExtenstions: Remove StackSizeInBytes
It's currently not used. Change-Id: I223a2e8add92a107b85518bcaf44bbd8a5e3fb9a Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -44,13 +44,11 @@ public:
|
|||||||
void setAsyncCallData(const Function &function, const Args &...args)
|
void setAsyncCallData(const Function &function, const Args &...args)
|
||||||
{
|
{
|
||||||
m_startHandler = [=] {
|
m_startHandler = [=] {
|
||||||
return Internal::runAsync_internal(m_threadPool, m_stackSize, m_priority,
|
return Utils::runAsync(m_threadPool, m_priority, function, args...);
|
||||||
function, args...);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
void setFutureSynchronizer(FutureSynchronizer *synchorizer) { m_synchronizer = synchorizer; }
|
void setFutureSynchronizer(FutureSynchronizer *synchorizer) { m_synchronizer = synchorizer; }
|
||||||
void setThreadPool(QThreadPool *pool) { m_threadPool = pool; }
|
void setThreadPool(QThreadPool *pool) { m_threadPool = pool; }
|
||||||
void setStackSizeInBytes(const StackSizeInBytes &size) { m_stackSize = size; }
|
|
||||||
void setPriority(QThread::Priority priority) { m_priority = priority; }
|
void setPriority(QThread::Priority priority) { m_priority = priority; }
|
||||||
|
|
||||||
void start()
|
void start()
|
||||||
@@ -75,7 +73,6 @@ private:
|
|||||||
FutureSynchronizer *m_synchronizer = nullptr;
|
FutureSynchronizer *m_synchronizer = nullptr;
|
||||||
QThreadPool *m_threadPool = nullptr;
|
QThreadPool *m_threadPool = nullptr;
|
||||||
QThread::Priority m_priority = QThread::InheritPriority;
|
QThread::Priority m_priority = QThread::InheritPriority;
|
||||||
StackSizeInBytes m_stackSize = {};
|
|
||||||
QFutureWatcher<ResultType> m_watcher;
|
QFutureWatcher<ResultType> m_watcher;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -16,7 +16,6 @@
|
|||||||
#include <QThreadPool>
|
#include <QThreadPool>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <optional>
|
|
||||||
|
|
||||||
// hasCallOperator & Co must be outside of any namespace
|
// hasCallOperator & Co must be outside of any namespace
|
||||||
// because of internal compiler error with MSVC2015 Update 2
|
// because of internal compiler error with MSVC2015 Update 2
|
||||||
@@ -38,8 +37,6 @@ struct hasCallOperator
|
|||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
using StackSizeInBytes = std::optional<uint>;
|
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -375,12 +372,10 @@ template<typename Function,
|
|||||||
typename... Args,
|
typename... Args,
|
||||||
typename ResultType = typename Internal::resultType<Function>::type>
|
typename ResultType = typename Internal::resultType<Function>::type>
|
||||||
QFuture<ResultType> runAsync_internal(QThreadPool *pool,
|
QFuture<ResultType> runAsync_internal(QThreadPool *pool,
|
||||||
StackSizeInBytes stackSize,
|
|
||||||
QThread::Priority priority,
|
QThread::Priority priority,
|
||||||
Function &&function,
|
Function &&function,
|
||||||
Args &&... args)
|
Args &&... args)
|
||||||
{
|
{
|
||||||
Q_ASSERT(!(pool && stackSize)); // stack size cannot be changed once a thread is started
|
|
||||||
auto job = new Internal::AsyncJob<ResultType,Function,Args...>
|
auto job = new Internal::AsyncJob<ResultType,Function,Args...>
|
||||||
(std::forward<Function>(function), std::forward<Args>(args)...);
|
(std::forward<Function>(function), std::forward<Args>(args)...);
|
||||||
job->setThreadPriority(priority);
|
job->setThreadPriority(priority);
|
||||||
@@ -390,8 +385,6 @@ QFuture<ResultType> runAsync_internal(QThreadPool *pool,
|
|||||||
pool->start(job);
|
pool->start(job);
|
||||||
} else {
|
} else {
|
||||||
auto thread = new Internal::RunnableThread(job);
|
auto thread = new Internal::RunnableThread(job);
|
||||||
if (stackSize)
|
|
||||||
thread->setStackSize(stackSize.value());
|
|
||||||
thread->moveToThread(qApp->thread()); // make sure thread gets deleteLater on main thread
|
thread->moveToThread(qApp->thread()); // make sure thread gets deleteLater on main thread
|
||||||
QObject::connect(thread, &QThread::finished, thread, &QObject::deleteLater);
|
QObject::connect(thread, &QThread::finished, thread, &QObject::deleteLater);
|
||||||
thread->start(priority);
|
thread->start(priority);
|
||||||
@@ -430,7 +423,6 @@ QFuture<ResultType>
|
|||||||
runAsync(QThreadPool *pool, QThread::Priority priority, Function &&function, Args&&... args)
|
runAsync(QThreadPool *pool, QThread::Priority priority, Function &&function, Args&&... args)
|
||||||
{
|
{
|
||||||
return Internal::runAsync_internal(pool,
|
return Internal::runAsync_internal(pool,
|
||||||
StackSizeInBytes(),
|
|
||||||
priority,
|
priority,
|
||||||
std::forward<Function>(function),
|
std::forward<Function>(function),
|
||||||
std::forward<Args>(args)...);
|
std::forward<Args>(args)...);
|
||||||
@@ -450,47 +442,6 @@ runAsync(QThread::Priority priority, Function &&function, Args&&... args)
|
|||||||
std::forward<Function>(function), std::forward<Args>(args)...);
|
std::forward<Function>(function), std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
Runs \a function with \a args in a new thread with given thread \a stackSize and
|
|
||||||
thread priority QThread::InheritPriority .
|
|
||||||
\sa runAsync(QThreadPool*,QThread::Priority,Function&&,Args&&...)
|
|
||||||
\sa QThread::Priority
|
|
||||||
\sa QThread::setStackSize
|
|
||||||
*/
|
|
||||||
template<typename Function,
|
|
||||||
typename... Args,
|
|
||||||
typename ResultType = typename Internal::resultType<Function>::type>
|
|
||||||
QFuture<ResultType> runAsync(StackSizeInBytes stackSize, Function &&function, Args &&... args)
|
|
||||||
{
|
|
||||||
return Internal::runAsync_internal(static_cast<QThreadPool *>(nullptr),
|
|
||||||
stackSize,
|
|
||||||
QThread::InheritPriority,
|
|
||||||
std::forward<Function>(function),
|
|
||||||
std::forward<Args>(args)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
Runs \a function with \a args in a new thread with given thread \a stackSize and
|
|
||||||
given thread \a priority.
|
|
||||||
\sa runAsync(QThreadPool*,QThread::Priority,Function&&,Args&&...)
|
|
||||||
\sa QThread::Priority
|
|
||||||
\sa QThread::setStackSize
|
|
||||||
*/
|
|
||||||
template<typename Function,
|
|
||||||
typename... Args,
|
|
||||||
typename ResultType = typename Internal::resultType<Function>::type>
|
|
||||||
QFuture<ResultType> runAsync(StackSizeInBytes stackSize,
|
|
||||||
QThread::Priority priority,
|
|
||||||
Function &&function,
|
|
||||||
Args &&... args)
|
|
||||||
{
|
|
||||||
return Internal::runAsync_internal(static_cast<QThreadPool *>(nullptr),
|
|
||||||
stackSize,
|
|
||||||
priority,
|
|
||||||
std::forward<Function>(function),
|
|
||||||
std::forward<Args>(args)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Runs \a function with \a args in a new thread with thread priority QThread::InheritPriority.
|
Runs \a function with \a args in a new thread with thread priority QThread::InheritPriority.
|
||||||
\sa runAsync(QThreadPool*,QThread::Priority,Function&&,Args&&...)
|
\sa runAsync(QThreadPool*,QThread::Priority,Function&&,Args&&...)
|
||||||
|
@@ -20,8 +20,6 @@ private slots:
|
|||||||
void moveOnlyType();
|
void moveOnlyType();
|
||||||
#endif
|
#endif
|
||||||
void threadPriority();
|
void threadPriority();
|
||||||
void threadSize();
|
|
||||||
void threadSizeAndPriority();
|
|
||||||
void runAsyncNoFutureInterface();
|
void runAsyncNoFutureInterface();
|
||||||
void crefFunction();
|
void crefFunction();
|
||||||
void onResultReady();
|
void onResultReady();
|
||||||
@@ -379,19 +377,6 @@ void tst_RunExtensions::threadPriority()
|
|||||||
QList<int>({0, 2, 1}));
|
QList<int>({0, 2, 1}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_RunExtensions::threadSize()
|
|
||||||
{
|
|
||||||
QCOMPARE(Utils::runAsync(Utils::StackSizeInBytes(1024 * 1024), report3).results(),
|
|
||||||
QList<int>({0, 2, 1}));
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_RunExtensions::threadSizeAndPriority()
|
|
||||||
{
|
|
||||||
QCOMPARE(Utils::runAsync(Utils::StackSizeInBytes(1024 * 1024), QThread::LowestPriority, report3)
|
|
||||||
.results(),
|
|
||||||
QList<int>({0, 2, 1}));
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_RunExtensions::runAsyncNoFutureInterface()
|
void tst_RunExtensions::runAsyncNoFutureInterface()
|
||||||
{
|
{
|
||||||
// free function pointer
|
// free function pointer
|
||||||
|
Reference in New Issue
Block a user