diff options
author | whd <7058128+superwhd@users.noreply.github.com> | 2022-07-26 11:02:55 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-25 20:02:55 -0700 |
commit | b0edec353e7dab39e6aadc8cab947e1a1bf1c932 (patch) | |
tree | 0f3e2104007763e5fc19e99b9b100316e9b71878 /src | |
parent | 7975f40e173ff639c29da3675a736a6fa6f2032b (diff) | |
download | ot-br-posix-b0edec353e7dab39e6aadc8cab947e1a1bf1c932.tar.gz |
[task-runner] fix `std::move` on const values (#1474)
There is an issue in `TaskRunner` that it declares `Task<void>` as a
const parameter in interfaces (e.g. `void TaskRunner::Post(const
Task<void> aTask)`). In the implementation it `std::move`s the `aTask`
and pushed it into an STL container. This `std::move` on the const
value doesn't lead to the move constructor of `Task<void>` which may
have better performance. It leads to the copy constructor instead. To
fix this, we need to make the `aTask` a non-const parameter.
Diffstat (limited to 'src')
-rw-r--r-- | src/common/task_runner.cpp | 6 | ||||
-rw-r--r-- | src/common/task_runner.hpp | 6 |
2 files changed, 6 insertions, 6 deletions
diff --git a/src/common/task_runner.cpp b/src/common/task_runner.cpp index 75a0cb56..4ee0328d 100644 --- a/src/common/task_runner.cpp +++ b/src/common/task_runner.cpp @@ -70,12 +70,12 @@ TaskRunner::~TaskRunner(void) } } -void TaskRunner::Post(const Task<void> aTask) +void TaskRunner::Post(Task<void> aTask) { Post(Milliseconds::zero(), std::move(aTask)); } -void TaskRunner::Post(Milliseconds aDelay, const Task<void> aTask) +void TaskRunner::Post(Milliseconds aDelay, Task<void> aTask) { PushTask(aDelay, std::move(aTask)); } @@ -129,7 +129,7 @@ void TaskRunner::Process(const MainloopContext &aMainloop) PopTasks(); } -void TaskRunner::PushTask(Milliseconds aDelay, const Task<void> aTask) +void TaskRunner::PushTask(Milliseconds aDelay, Task<void> aTask) { ssize_t rval; const uint8_t kOne = 1; diff --git a/src/common/task_runner.hpp b/src/common/task_runner.hpp index f9a9a730..fe81e9c1 100644 --- a/src/common/task_runner.hpp +++ b/src/common/task_runner.hpp @@ -83,7 +83,7 @@ public: * @param[in] aTask The task to be executed. * */ - void Post(const Task<void> aTask); + void Post(Task<void> aTask); /** * This method posts a task to the task runner and returns immediately. @@ -94,7 +94,7 @@ public: * @param[in] aTask The task to be executed. * */ - void Post(Milliseconds aDelay, const Task<void> aTask); + void Post(Milliseconds aDelay, Task<void> aTask); /** * This method posts a task and waits for the completion of the task. @@ -154,7 +154,7 @@ private: Task<void> mTask; }; - void PushTask(Milliseconds aDelay, const Task<void> aTask); + void PushTask(Milliseconds aDelay, Task<void> aTask); void PopTasks(void); // The event fds which are used to wakeup the mainloop |