Cleaning up C++14 move into lambda TODOs.

Bug: webrtc:10945
Change-Id: I4d2f358b0e33b37e4b4f7bfcf3f6cd55e8d46bf9
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/153240
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29212}
This commit is contained in:
Sebastian Jansson
2019-09-17 20:29:59 +02:00
committed by Commit Bot
parent 368d002e48
commit 86314cfb5d
8 changed files with 83 additions and 172 deletions

View File

@ -60,18 +60,6 @@ class MoveOnlyClosure {
private:
MockClosure* mock_;
};
// Helper closure class to stop repeating task on a task queue. This is
// equivalent to [handle{move(handle)}] { handle.Stop(); } in c++14.
class TaskHandleStopper {
public:
explicit TaskHandleStopper(RepeatingTaskHandle handle)
: handle_(std::move(handle)) {}
void operator()() { handle_.Stop(); }
private:
RepeatingTaskHandle handle_;
};
} // namespace
TEST(RepeatingTaskTest, TaskIsStoppedOnStop) {
@ -91,7 +79,8 @@ TEST(RepeatingTaskTest, TaskIsStoppedOnStop) {
Sleep(kShortInterval * (kShortIntervalCount + kMargin));
EXPECT_EQ(counter.load(), kShortIntervalCount);
task_queue.PostTask(TaskHandleStopper(std::move(handle)));
task_queue.PostTask(
[handle = std::move(handle)]() mutable { handle.Stop(); });
// Sleep long enough that the task would run at least once more if not
// stopped.
Sleep(kLongInterval * 2);
@ -144,7 +133,8 @@ TEST(RepeatingTaskTest, CancelDelayedTaskBeforeItRuns) {
TaskQueueForTest task_queue("queue");
auto handle = RepeatingTaskHandle::DelayedStart(
task_queue.Get(), TimeDelta::ms(100), MoveOnlyClosure(&mock));
task_queue.PostTask(TaskHandleStopper(std::move(handle)));
task_queue.PostTask(
[handle = std::move(handle)]() mutable { handle.Stop(); });
EXPECT_TRUE(done.Wait(kTimeout.ms()));
}
@ -156,7 +146,8 @@ TEST(RepeatingTaskTest, CancelTaskAfterItRuns) {
TaskQueueForTest task_queue("queue");
auto handle =
RepeatingTaskHandle::Start(task_queue.Get(), MoveOnlyClosure(&mock));
task_queue.PostTask(TaskHandleStopper(std::move(handle)));
task_queue.PostTask(
[handle = std::move(handle)]() mutable { handle.Stop(); });
EXPECT_TRUE(done.Wait(kTimeout.ms()));
}
@ -223,9 +214,11 @@ TEST(RepeatingTaskTest, Example) {
RepeatingTaskHandle handle;
object->StartPeriodicTask(&handle, task_queue.Get());
// Restart the task
task_queue.PostTask(TaskHandleStopper(std::move(handle)));
task_queue.PostTask(
[handle = std::move(handle)]() mutable { handle.Stop(); });
object->StartPeriodicTask(&handle, task_queue.Get());
task_queue.PostTask(TaskHandleStopper(std::move(handle)));
task_queue.PostTask(
[handle = std::move(handle)]() mutable { handle.Stop(); });
struct Destructor {
void operator()() { object.reset(); }
std::unique_ptr<ObjectOnTaskQueue> object;