Commit dd34a877 authored by Gabriel Charette's avatar Gabriel Charette Committed by Commit Bot

Reland [base] Require task posters to specify an explicit destination

This patch makes it a requirement for all task traits to specify their
thread affinity. Previously task traits that did not name a specific
thread would implicitly run on the thread pool, which could be
surprising. To make this more obvious, thread pool tasks must now use
the base::ThreadPool() trait.

This is the final reland of
https://chromium-review.googlesource.com/c/chromium/src/+/1635827
(will attempt to fix errors that caused original revert before
 relanding).

Bug: 968047
Change-Id: Ice339db270a27815b2be68200930e5bc105e8a96
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1759056
Commit-Queue: Gabriel Charette <gab@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688782}
parent 7132db6a
......@@ -255,7 +255,16 @@ class BASE_EXPORT TaskTraits {
may_block_(trait_helpers::HasTrait<MayBlock, ArgTypes...>()),
with_base_sync_primitives_(
trait_helpers::HasTrait<WithBaseSyncPrimitives, ArgTypes...>()),
use_thread_pool_(trait_helpers::HasTrait<ThreadPool, ArgTypes...>()) {}
use_thread_pool_(trait_helpers::HasTrait<ThreadPool, ArgTypes...>()) {
constexpr bool has_thread_pool =
trait_helpers::HasTrait<ThreadPool, ArgTypes...>();
constexpr bool has_extension =
!trait_helpers::AreValidTraits<ValidTrait, ArgTypes...>::value;
static_assert(
has_thread_pool ^ has_extension,
"Traits must explicitly specify a destination (e.g. ThreadPool or a "
"named thread like BrowserThread)");
}
constexpr TaskTraits(const TaskTraits& other) = default;
TaskTraits& operator=(const TaskTraits& other) = default;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment