Improve argument name for std::function argument

Less \a fun though.

Note using references in this API would just duplicate the API, but
still end up with a copy when creating the QRunnable. By having the
copy apparent directly in the API, we not only save the duplication,
we also hint to the caller to use move if they want to avoid a copy.

Change-Id: If11476d4b38853839c1e87e0339807a1798fc875
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Allan Sandfeld Jensen 2020-02-25 16:16:42 +01:00
parent 165d2f09cd
commit 23c5fc1d2f
4 changed files with 19 additions and 19 deletions

View File

@ -116,29 +116,29 @@ QRunnable::~QRunnable()
class FunctionRunnable : public QRunnable
{
std::function<void()> m_functor;
std::function<void()> m_functionToRun;
public:
FunctionRunnable(std::function<void()> functor) : m_functor(std::move(functor))
FunctionRunnable(std::function<void()> functionToRun) : m_functionToRun(std::move(functionToRun))
{
}
void run() override
{
m_functor();
m_functionToRun();
}
};
/*!
\since 5.15
Creates a QRunnable that calls \a fun in run().
Creates a QRunnable that calls \a functionToRun in run().
Auto-deletion is enabled by default.
\sa run(), autoDelete()
*/
QRunnable *QRunnable::create(std::function<void()> fun)
QRunnable *QRunnable::create(std::function<void()> functionToRun)
{
return new FunctionRunnable(std::move(fun));
return new FunctionRunnable(std::move(functionToRun));
}
QT_END_NAMESPACE

View File

@ -60,7 +60,7 @@ public:
QRunnable() : ref(0) { }
virtual ~QRunnable();
static QRunnable *create(std::function<void()> fun);
static QRunnable *create(std::function<void()> functionToRun);
bool autoDelete() const { return ref != -1; }
void setAutoDelete(bool _autoDelete) { ref = _autoDelete ? 0 : -1; }

View File

@ -515,16 +515,16 @@ void QThreadPool::start(QRunnable *runnable, int priority)
\overload
\since 5.15
Reserves a thread and uses it to run \a fun, unless this thread will
Reserves a thread and uses it to run \a functionToRun, unless this thread will
make the current thread count exceed maxThreadCount(). In that case,
\a fun is added to a run queue instead. The \a priority argument can
\a functionToRun is added to a run queue instead. The \a priority argument can
be used to control the run queue's order of execution.
*/
void QThreadPool::start(std::function<void()> fun, int priority)
void QThreadPool::start(std::function<void()> functionToRun, int priority)
{
if (!fun)
if (!functionToRun)
return;
start(QRunnable::create(std::move(fun)), priority);
start(QRunnable::create(std::move(functionToRun)), priority);
}
/*!
@ -561,17 +561,17 @@ bool QThreadPool::tryStart(QRunnable *runnable)
/*!
\overload
\since 5.15
Attempts to reserve a thread to run \a fun.
Attempts to reserve a thread to run \a functionToRun.
If no threads are available at the time of calling, then this function
does nothing and returns \c false. Otherwise, \a fun is run immediately
does nothing and returns \c false. Otherwise, \a functionToRun is run immediately
using one available thread and this function returns \c true.
*/
bool QThreadPool::tryStart(std::function<void()> fun)
bool QThreadPool::tryStart(std::function<void()> functionToRun)
{
if (!fun)
if (!functionToRun)
return false;
return tryStart(QRunnable::create(std::move(fun)));
return tryStart(QRunnable::create(std::move(functionToRun)));
}
/*! \property QThreadPool::expiryTimeout

View File

@ -72,8 +72,8 @@ public:
void start(QRunnable *runnable, int priority = 0);
bool tryStart(QRunnable *runnable);
void start(std::function<void()> fun, int priority = 0);
bool tryStart(std::function<void()> fun);
void start(std::function<void()> functionToRun, int priority = 0);
bool tryStart(std::function<void()> functionToRun);
int expiryTimeout() const;
void setExpiryTimeout(int expiryTimeout);