diff options
author | Mathieu Chartier <mathieuc@google.com> | 2017-12-21 23:52:25 +0000 |
---|---|---|
committer | Mathieu Chartier <mathieuc@google.com> | 2017-12-21 23:54:27 +0000 |
commit | 8abac493f652a1835c61e538919820aa77658a39 (patch) | |
tree | a9d13e0b40d89d8960e80b71a7c21e639ea6c2d5 /base/threading | |
parent | 618a67a769e94d35a8944051400310c5710a7884 (diff) | |
download | libchrome-8abac493f652a1835c61e538919820aa77658a39.tar.gz |
Revert "Uprev the library to r462023 from Chromium"
This reverts commit fe2f52931e8e50253d06329d7bf0a4164c7ba580.
Reason for revert: Mac build broken
Change-Id: I3abd2ba6874ec5bd283ba17c36ad0b35bcc3d374
Diffstat (limited to 'base/threading')
-rw-r--r-- | base/threading/post_task_and_reply_impl.h | 2 | ||||
-rw-r--r-- | base/threading/sequenced_worker_pool.cc | 95 | ||||
-rw-r--r-- | base/threading/sequenced_worker_pool.h | 19 | ||||
-rw-r--r-- | base/threading/worker_pool.cc | 16 | ||||
-rw-r--r-- | base/threading/worker_pool.h | 3 | ||||
-rw-r--r-- | base/threading/worker_pool_posix.cc | 17 | ||||
-rw-r--r-- | base/threading/worker_pool_posix.h | 5 |
7 files changed, 77 insertions, 80 deletions
diff --git a/base/threading/post_task_and_reply_impl.h b/base/threading/post_task_and_reply_impl.h index a02c32ec8c..696b668a4c 100644 --- a/base/threading/post_task_and_reply_impl.h +++ b/base/threading/post_task_and_reply_impl.h @@ -34,7 +34,7 @@ class BASE_EXPORT PostTaskAndReplyImpl { private: virtual bool PostTask(const tracked_objects::Location& from_here, - Closure task) = 0; + const Closure& task) = 0; }; } // namespace internal diff --git a/base/threading/sequenced_worker_pool.cc b/base/threading/sequenced_worker_pool.cc index 866a8b3b3b..ce594cd7fb 100644 --- a/base/threading/sequenced_worker_pool.cc +++ b/base/threading/sequenced_worker_pool.cc @@ -144,7 +144,7 @@ class SequencedWorkerPoolTaskRunner : public TaskRunner { // TaskRunner implementation bool PostDelayedTask(const tracked_objects::Location& from_here, - Closure task, + const Closure& task, TimeDelta delay) override; bool RunsTasksOnCurrentThread() const override; @@ -168,13 +168,13 @@ SequencedWorkerPoolTaskRunner::~SequencedWorkerPoolTaskRunner() { bool SequencedWorkerPoolTaskRunner::PostDelayedTask( const tracked_objects::Location& from_here, - Closure task, + const Closure& task, TimeDelta delay) { if (delay.is_zero()) { - return pool_->PostWorkerTaskWithShutdownBehavior(from_here, std::move(task), - shutdown_behavior_); + return pool_->PostWorkerTaskWithShutdownBehavior( + from_here, task, shutdown_behavior_); } - return pool_->PostDelayedWorkerTask(from_here, std::move(task), delay); + return pool_->PostDelayedWorkerTask(from_here, task, delay); } bool SequencedWorkerPoolTaskRunner::RunsTasksOnCurrentThread() const { @@ -198,13 +198,13 @@ class SequencedWorkerPool::PoolSequencedTaskRunner // TaskRunner implementation bool PostDelayedTask(const tracked_objects::Location& from_here, - Closure task, + const Closure& task, TimeDelta delay) override; bool RunsTasksOnCurrentThread() const override; // SequencedTaskRunner implementation bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, - Closure task, + const Closure& task, TimeDelta delay) override; private: @@ -231,16 +231,15 @@ SequencedWorkerPool::PoolSequencedTaskRunner:: SequencedWorkerPool::PoolSequencedTaskRunner:: ~PoolSequencedTaskRunner() = default; -bool SequencedWorkerPool::PoolSequencedTaskRunner::PostDelayedTask( - const tracked_objects::Location& from_here, - Closure task, - TimeDelta delay) { +bool SequencedWorkerPool::PoolSequencedTaskRunner:: + PostDelayedTask(const tracked_objects::Location& from_here, + const Closure& task, + TimeDelta delay) { if (delay.is_zero()) { return pool_->PostSequencedWorkerTaskWithShutdownBehavior( - token_, from_here, std::move(task), shutdown_behavior_); + token_, from_here, task, shutdown_behavior_); } - return pool_->PostDelayedSequencedWorkerTask(token_, from_here, - std::move(task), delay); + return pool_->PostDelayedSequencedWorkerTask(token_, from_here, task, delay); } bool SequencedWorkerPool::PoolSequencedTaskRunner:: @@ -248,13 +247,13 @@ bool SequencedWorkerPool::PoolSequencedTaskRunner:: return pool_->IsRunningSequenceOnCurrentThread(token_); } -bool SequencedWorkerPool::PoolSequencedTaskRunner::PostNonNestableDelayedTask( - const tracked_objects::Location& from_here, - Closure task, - TimeDelta delay) { +bool SequencedWorkerPool::PoolSequencedTaskRunner:: + PostNonNestableDelayedTask(const tracked_objects::Location& from_here, + const Closure& task, + TimeDelta delay) { // There's no way to run nested tasks, so simply forward to // PostDelayedTask. - return PostDelayedTask(from_here, std::move(task), delay); + return PostDelayedTask(from_here, task, delay); } // Worker --------------------------------------------------------------------- @@ -353,7 +352,7 @@ class SequencedWorkerPool::Inner { SequenceToken sequence_token, WorkerShutdown shutdown_behavior, const tracked_objects::Location& from_here, - Closure task, + const Closure& task, TimeDelta delay); bool RunsTasksOnCurrentThread() const; @@ -697,7 +696,7 @@ bool SequencedWorkerPool::Inner::PostTask( SequenceToken sequence_token, WorkerShutdown shutdown_behavior, const tracked_objects::Location& from_here, - Closure task, + const Closure& task, TimeDelta delay) { // TODO(fdoray): Uncomment this DCHECK. It is initially commented to avoid a // revert of the CL that adds debug::DumpWithoutCrashing() if it fails on the @@ -711,9 +710,9 @@ bool SequencedWorkerPool::Inner::PostTask( sequenced.sequence_token_id = sequence_token.id_; sequenced.shutdown_behavior = shutdown_behavior; sequenced.posted_from = from_here; - sequenced.task = shutdown_behavior == BLOCK_SHUTDOWN - ? base::MakeCriticalClosure(std::move(task)) - : std::move(task); + sequenced.task = + shutdown_behavior == BLOCK_SHUTDOWN ? + base::MakeCriticalClosure(task) : task; sequenced.time_to_run = TimeTicks::Now() + delay; int create_thread_id = 0; @@ -1044,7 +1043,7 @@ void SequencedWorkerPool::Inner::ThreadLoop(Worker* this_worker) { tracked_objects::TaskStopwatch stopwatch; stopwatch.Start(); - std::move(task.task).Run(); + task.task.Run(); stopwatch.Stop(); tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking( @@ -1055,7 +1054,7 @@ void SequencedWorkerPool::Inner::ThreadLoop(Worker* this_worker) { // Also, do it before calling reset_running_task_info() so // that sequence-checking from within the task's destructor // still works. - DCHECK(!task.task); + task.task = Closure(); this_worker->reset_running_task_info(); } @@ -1563,71 +1562,71 @@ SequencedWorkerPool::GetTaskRunnerWithShutdownBehavior( bool SequencedWorkerPool::PostWorkerTask( const tracked_objects::Location& from_here, - Closure task) { - return inner_->PostTask(NULL, SequenceToken(), BLOCK_SHUTDOWN, from_here, - std::move(task), TimeDelta()); + const Closure& task) { + return inner_->PostTask(NULL, SequenceToken(), BLOCK_SHUTDOWN, + from_here, task, TimeDelta()); } bool SequencedWorkerPool::PostDelayedWorkerTask( const tracked_objects::Location& from_here, - Closure task, + const Closure& task, TimeDelta delay) { WorkerShutdown shutdown_behavior = delay.is_zero() ? BLOCK_SHUTDOWN : SKIP_ON_SHUTDOWN; - return inner_->PostTask(NULL, SequenceToken(), shutdown_behavior, from_here, - std::move(task), delay); + return inner_->PostTask(NULL, SequenceToken(), shutdown_behavior, + from_here, task, delay); } bool SequencedWorkerPool::PostWorkerTaskWithShutdownBehavior( const tracked_objects::Location& from_here, - Closure task, + const Closure& task, WorkerShutdown shutdown_behavior) { - return inner_->PostTask(NULL, SequenceToken(), shutdown_behavior, from_here, - std::move(task), TimeDelta()); + return inner_->PostTask(NULL, SequenceToken(), shutdown_behavior, + from_here, task, TimeDelta()); } bool SequencedWorkerPool::PostSequencedWorkerTask( SequenceToken sequence_token, const tracked_objects::Location& from_here, - Closure task) { - return inner_->PostTask(NULL, sequence_token, BLOCK_SHUTDOWN, from_here, - std::move(task), TimeDelta()); + const Closure& task) { + return inner_->PostTask(NULL, sequence_token, BLOCK_SHUTDOWN, + from_here, task, TimeDelta()); } bool SequencedWorkerPool::PostDelayedSequencedWorkerTask( SequenceToken sequence_token, const tracked_objects::Location& from_here, - Closure task, + const Closure& task, TimeDelta delay) { WorkerShutdown shutdown_behavior = delay.is_zero() ? BLOCK_SHUTDOWN : SKIP_ON_SHUTDOWN; - return inner_->PostTask(NULL, sequence_token, shutdown_behavior, from_here, - std::move(task), delay); + return inner_->PostTask(NULL, sequence_token, shutdown_behavior, + from_here, task, delay); } bool SequencedWorkerPool::PostNamedSequencedWorkerTask( const std::string& token_name, const tracked_objects::Location& from_here, - Closure task) { + const Closure& task) { DCHECK(!token_name.empty()); return inner_->PostTask(&token_name, SequenceToken(), BLOCK_SHUTDOWN, - from_here, std::move(task), TimeDelta()); + from_here, task, TimeDelta()); } bool SequencedWorkerPool::PostSequencedWorkerTaskWithShutdownBehavior( SequenceToken sequence_token, const tracked_objects::Location& from_here, - Closure task, + const Closure& task, WorkerShutdown shutdown_behavior) { - return inner_->PostTask(NULL, sequence_token, shutdown_behavior, from_here, - std::move(task), TimeDelta()); + return inner_->PostTask(NULL, sequence_token, shutdown_behavior, + from_here, task, TimeDelta()); } bool SequencedWorkerPool::PostDelayedTask( const tracked_objects::Location& from_here, - Closure task, + const Closure& task, TimeDelta delay) { - return PostDelayedWorkerTask(from_here, std::move(task), delay); + return PostDelayedWorkerTask(from_here, task, delay); } bool SequencedWorkerPool::RunsTasksOnCurrentThread() const { diff --git a/base/threading/sequenced_worker_pool.h b/base/threading/sequenced_worker_pool.h index 8cdeb0b5db..0d42de9138 100644 --- a/base/threading/sequenced_worker_pool.h +++ b/base/threading/sequenced_worker_pool.h @@ -12,7 +12,7 @@ #include <string> #include "base/base_export.h" -#include "base/callback.h" +#include "base/callback_forward.h" #include "base/compiler_specific.h" #include "base/macros.h" #include "base/memory/ref_counted.h" @@ -275,7 +275,8 @@ class BASE_EXPORT SequencedWorkerPool : public TaskRunner { // // Returns true if the task was posted successfully. This may fail during // shutdown regardless of the specified ShutdownBehavior. - bool PostWorkerTask(const tracked_objects::Location& from_here, Closure task); + bool PostWorkerTask(const tracked_objects::Location& from_here, + const Closure& task); // Same as PostWorkerTask but allows a delay to be specified (although doing // so changes the shutdown behavior). The task will be run after the given @@ -287,13 +288,13 @@ class BASE_EXPORT SequencedWorkerPool : public TaskRunner { // task will be guaranteed to run to completion before shutdown // (BLOCK_SHUTDOWN semantics). bool PostDelayedWorkerTask(const tracked_objects::Location& from_here, - Closure task, + const Closure& task, TimeDelta delay); // Same as PostWorkerTask but allows specification of the shutdown behavior. bool PostWorkerTaskWithShutdownBehavior( const tracked_objects::Location& from_here, - Closure task, + const Closure& task, WorkerShutdown shutdown_behavior); // Like PostWorkerTask above, but provides sequencing semantics. This means @@ -309,13 +310,13 @@ class BASE_EXPORT SequencedWorkerPool : public TaskRunner { // shutdown regardless of the specified ShutdownBehavior. bool PostSequencedWorkerTask(SequenceToken sequence_token, const tracked_objects::Location& from_here, - Closure task); + const Closure& task); // Like PostSequencedWorkerTask above, but allows you to specify a named // token, which saves an extra call to GetNamedSequenceToken. bool PostNamedSequencedWorkerTask(const std::string& token_name, const tracked_objects::Location& from_here, - Closure task); + const Closure& task); // Same as PostSequencedWorkerTask but allows a delay to be specified // (although doing so changes the shutdown behavior). The task will be run @@ -329,7 +330,7 @@ class BASE_EXPORT SequencedWorkerPool : public TaskRunner { bool PostDelayedSequencedWorkerTask( SequenceToken sequence_token, const tracked_objects::Location& from_here, - Closure task, + const Closure& task, TimeDelta delay); // Same as PostSequencedWorkerTask but allows specification of the shutdown @@ -337,12 +338,12 @@ class BASE_EXPORT SequencedWorkerPool : public TaskRunner { bool PostSequencedWorkerTaskWithShutdownBehavior( SequenceToken sequence_token, const tracked_objects::Location& from_here, - Closure task, + const Closure& task, WorkerShutdown shutdown_behavior); // TaskRunner implementation. Forwards to PostDelayedWorkerTask(). bool PostDelayedTask(const tracked_objects::Location& from_here, - Closure task, + const Closure& task, TimeDelta delay) override; bool RunsTasksOnCurrentThread() const override; diff --git a/base/threading/worker_pool.cc b/base/threading/worker_pool.cc index bc313ce25b..d47037d79a 100644 --- a/base/threading/worker_pool.cc +++ b/base/threading/worker_pool.cc @@ -27,8 +27,8 @@ class PostTaskAndReplyWorkerPool : public internal::PostTaskAndReplyImpl { private: bool PostTask(const tracked_objects::Location& from_here, - Closure task) override { - return WorkerPool::PostTask(from_here, std::move(task), task_is_slow_); + const Closure& task) override { + return WorkerPool::PostTask(from_here, task, task_is_slow_); } bool task_is_slow_; @@ -45,7 +45,7 @@ class WorkerPoolTaskRunner : public TaskRunner { // TaskRunner implementation bool PostDelayedTask(const tracked_objects::Location& from_here, - Closure task, + const Closure& task, TimeDelta delay) override; bool RunsTasksOnCurrentThread() const override; @@ -56,7 +56,7 @@ class WorkerPoolTaskRunner : public TaskRunner { // zero because non-zero delays are not supported. bool PostDelayedTaskAssertZeroDelay( const tracked_objects::Location& from_here, - Closure task, + const Closure& task, base::TimeDelta delay); const bool tasks_are_slow_; @@ -73,9 +73,9 @@ WorkerPoolTaskRunner::~WorkerPoolTaskRunner() { bool WorkerPoolTaskRunner::PostDelayedTask( const tracked_objects::Location& from_here, - Closure task, + const Closure& task, TimeDelta delay) { - return PostDelayedTaskAssertZeroDelay(from_here, std::move(task), delay); + return PostDelayedTaskAssertZeroDelay(from_here, task, delay); } bool WorkerPoolTaskRunner::RunsTasksOnCurrentThread() const { @@ -84,11 +84,11 @@ bool WorkerPoolTaskRunner::RunsTasksOnCurrentThread() const { bool WorkerPoolTaskRunner::PostDelayedTaskAssertZeroDelay( const tracked_objects::Location& from_here, - Closure task, + const Closure& task, base::TimeDelta delay) { DCHECK_EQ(delay.InMillisecondsRoundedUp(), 0) << "WorkerPoolTaskRunner does not support non-zero delays"; - return WorkerPool::PostTask(from_here, std::move(task), tasks_are_slow_); + return WorkerPool::PostTask(from_here, task, tasks_are_slow_); } struct TaskRunnerHolder { diff --git a/base/threading/worker_pool.h b/base/threading/worker_pool.h index d97dbd6a69..865948e437 100644 --- a/base/threading/worker_pool.h +++ b/base/threading/worker_pool.h @@ -32,8 +32,7 @@ class BASE_EXPORT WorkerPool { // false if |task| could not be posted to a worker thread. Regardless of // return value, ownership of |task| is transferred to the worker pool. static bool PostTask(const tracked_objects::Location& from_here, - Closure task, - bool task_is_slow); + const base::Closure& task, bool task_is_slow); // Just like TaskRunner::PostTaskAndReply, except the destination // for |task| is a worker thread and you can specify |task_is_slow| just diff --git a/base/threading/worker_pool_posix.cc b/base/threading/worker_pool_posix.cc index 2133ba98e2..0e19a1a0fe 100644 --- a/base/threading/worker_pool_posix.cc +++ b/base/threading/worker_pool_posix.cc @@ -6,8 +6,6 @@ #include <stddef.h> -#include <utility> - #include "base/bind.h" #include "base/callback.h" #include "base/lazy_instance.h" @@ -49,7 +47,7 @@ class WorkerPoolImpl { ~WorkerPoolImpl() = delete; void PostTask(const tracked_objects::Location& from_here, - base::Closure task, + const base::Closure& task, bool task_is_slow); private: @@ -61,9 +59,9 @@ WorkerPoolImpl::WorkerPoolImpl() kIdleSecondsBeforeExit)) {} void WorkerPoolImpl::PostTask(const tracked_objects::Location& from_here, - base::Closure task, + const base::Closure& task, bool /*task_is_slow*/) { - pool_->PostTask(from_here, std::move(task)); + pool_->PostTask(from_here, task); } base::LazyInstance<WorkerPoolImpl>::Leaky g_lazy_worker_pool = @@ -114,10 +112,9 @@ void WorkerThread::ThreadMain() { // static bool WorkerPool::PostTask(const tracked_objects::Location& from_here, - base::Closure task, + const base::Closure& task, bool task_is_slow) { - g_lazy_worker_pool.Pointer()->PostTask(from_here, std::move(task), - task_is_slow); + g_lazy_worker_pool.Pointer()->PostTask(from_here, task, task_is_slow); return true; } @@ -140,8 +137,8 @@ PosixDynamicThreadPool::~PosixDynamicThreadPool() { void PosixDynamicThreadPool::PostTask( const tracked_objects::Location& from_here, - base::Closure task) { - PendingTask pending_task(from_here, std::move(task)); + const base::Closure& task) { + PendingTask pending_task(from_here, task); AddTask(&pending_task); } diff --git a/base/threading/worker_pool_posix.h b/base/threading/worker_pool_posix.h index cfa50c21dd..d65ae8f8cf 100644 --- a/base/threading/worker_pool_posix.h +++ b/base/threading/worker_pool_posix.h @@ -28,7 +28,7 @@ #include <queue> #include <string> -#include "base/callback.h" +#include "base/callback_forward.h" #include "base/location.h" #include "base/macros.h" #include "base/memory/ref_counted.h" @@ -51,7 +51,8 @@ class BASE_EXPORT PosixDynamicThreadPool int idle_seconds_before_exit); // Adds |task| to the thread pool. - void PostTask(const tracked_objects::Location& from_here, Closure task); + void PostTask(const tracked_objects::Location& from_here, + const Closure& task); // Worker thread method to wait for up to |idle_seconds_before_exit| for more // work from the thread pool. Returns NULL if no work is available. |