Make PendingTask move-only and pass it by value on retaining params
PendingTask is copied several time when it's created and consumed in
MessageLoop, and each copy operation implies two atomicops on ref-count
bump on Callback. This CL removes them by migrating to pass-by-move.
Chrome has performed ~100k atomic ops for Callback ref-count (50k inc
and 50k dec) on the first 15s after boot before this CL, and it will
be reduced to ~50k after this CL.
Review-Url: https://codereview.chromium.org/1886453003
Cr-Commit-Position: refs/heads/master@{#404229}
diff --git a/base/pending_task.h b/base/pending_task.h
index c31ab9a..5761653 100644
--- a/base/pending_task.h
+++ b/base/pending_task.h
@@ -19,14 +19,16 @@
// for use by classes that queue and execute tasks.
struct BASE_EXPORT PendingTask : public TrackingInfo {
PendingTask(const tracked_objects::Location& posted_from,
- const Closure& task);
+ Closure task);
PendingTask(const tracked_objects::Location& posted_from,
- const Closure& task,
+ Closure task,
TimeTicks delayed_run_time,
bool nestable);
- PendingTask(const PendingTask& other);
+ PendingTask(PendingTask&& other);
~PendingTask();
+ PendingTask& operator=(PendingTask&& other);
+
// Used to support sorting.
bool operator<(const PendingTask& other) const;