Commit 133f8a07 authored by Alexander Timin's avatar Alexander Timin Committed by Commit Bot

[scheduler] Rename blink::background_scheduler to worker_pool

The term "background" is confusing as it refers to a thread with a
specific priority. Use worker_pool instead to refer to
non-main-thread scheduler.

R=haraken@chromium.org,gab@chromium.org

Change-Id: Ia72090e39a3354cd14c539e64475cf661db15cd7
Reviewed-on: https://chromium-review.googlesource.com/c/1282396
Commit-Queue: Alexander Timin <altimin@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarSami Kyöstilä <skyostil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#630516}
parent b7a70665
......@@ -21,9 +21,9 @@
#include "third_party/blink/renderer/platform/loader/fetch/cached_metadata.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/scheduler/public/background_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/public/worker_pool.h"
#include "third_party/blink/renderer/platform/shared_buffer.h"
#include "third_party/blink/renderer/platform/wtf/deque.h"
#include "third_party/blink/renderer/platform/wtf/text/text_encoding_registry.h"
......@@ -445,7 +445,7 @@ void ScriptStreamer::NotifyAppendData() {
// cancel the task.
//
// TODO(leszeks): Decrease the priority of these tasks where possible.
background_scheduler::PostOnBackgroundThreadWithTraits(
worker_pool::PostTaskWithTraits(
FROM_HERE, {base::TaskPriority::USER_BLOCKING, base::MayBlock()},
CrossThreadBind(RunBlockingScriptStreamingTask,
WTF::Passed(std::move(script_streaming_task)),
......@@ -498,7 +498,7 @@ void ScriptStreamer::NotifyFinished() {
// The task creation shouldn't fail, since it didn't fail before during
// NotifyAppendData.
CHECK(script_streaming_task);
background_scheduler::PostOnBackgroundThreadWithTraits(
worker_pool::PostTaskWithTraits(
FROM_HERE, {base::TaskPriority::USER_BLOCKING},
CrossThreadBind(RunNonBlockingScriptStreamingTask,
WTF::Passed(std::move(script_streaming_task)),
......
......@@ -20,10 +20,10 @@
#include "third_party/blink/renderer/platform/graphics/skia/skia_utils.h"
#include "third_party/blink/renderer/platform/histogram.h"
#include "third_party/blink/renderer/platform/image-encoders/image_encoder_utils.h"
#include "third_party/blink/renderer/platform/scheduler/public/background_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/public/worker_pool.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/time.h"
#include "third_party/skia/include/core/SkSurface.h"
......@@ -330,7 +330,7 @@ void CanvasAsyncBlobCreator::ScheduleAsyncBlobCreation(const double& quality) {
WrapPersistent(this)));
} else {
background_scheduler::PostOnBackgroundThread(
worker_pool::PostTask(
FROM_HERE,
CrossThreadBind(&CanvasAsyncBlobCreator::EncodeImageOnEncoderThread,
WrapCrossThreadPersistent(this), quality));
......
......@@ -17,8 +17,8 @@
#include "third_party/blink/renderer/platform/graphics/canvas_resource_provider.h"
#include "third_party/blink/renderer/platform/graphics/skia/skia_utils.h"
#include "third_party/blink/renderer/platform/image-decoders/image_decoder.h"
#include "third_party/blink/renderer/platform/scheduler/public/background_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/public/worker_pool.h"
#include "third_party/blink/renderer/platform/wtf/saturated_arithmetic.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkImageInfo.h"
......@@ -1004,7 +1004,7 @@ ScriptPromise ImageBitmap::CreateAsync(ImageElementBase* image,
draw_dst_rect, parsed_options.flip_y);
std::unique_ptr<ParsedOptions> passed_parsed_options =
std::make_unique<ParsedOptions>(parsed_options);
background_scheduler::PostOnBackgroundThread(
worker_pool::PostTask(
FROM_HERE,
CrossThreadBind(&RasterizeImageOnBackgroundThread,
WrapCrossThreadPersistent(resolver),
......
......@@ -52,9 +52,9 @@
#include "third_party/blink/renderer/platform/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/histogram.h"
#include "third_party/blink/renderer/platform/image-decoders/image_decoder.h"
#include "third_party/blink/renderer/platform/scheduler/public/background_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread.h"
#include "third_party/blink/renderer/platform/scheduler/public/worker_pool.h"
#include "third_party/blink/renderer/platform/shared_buffer.h"
#include "v8/include/v8.h"
......@@ -314,7 +314,7 @@ void ImageBitmapFactories::ImageBitmapLoader::ScheduleAsyncImageBitmapDecoding(
DOMArrayBuffer* array_buffer) {
scoped_refptr<base::SingleThreadTaskRunner> task_runner =
Thread::Current()->GetTaskRunner();
background_scheduler::PostOnBackgroundThread(
worker_pool::PostTask(
FROM_HERE,
CrossThreadBind(
&ImageBitmapFactories::ImageBitmapLoader::DecodeImageOnDecoderThread,
......
......@@ -21,8 +21,8 @@
#include "third_party/blink/renderer/platform/image-decoders/segment_reader.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_loader_options.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_request.h"
#include "third_party/blink/renderer/platform/scheduler/public/background_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/public/worker_pool.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/wtf/text/string_impl.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
......@@ -164,7 +164,7 @@ void BackgroundFetchIconLoader::DidFinishLoading(
scoped_refptr<base::SingleThreadTaskRunner> task_runner =
Thread::Current()->GetTaskRunner();
background_scheduler::PostOnBackgroundThread(
worker_pool::PostTask(
FROM_HERE,
CrossThreadBind(
&BackgroundFetchIconLoader::DecodeAndResizeImageOnBackgroundThread,
......
......@@ -21,9 +21,9 @@
#include "third_party/blink/renderer/platform/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/image-decoders/image_decoder.h"
#include "third_party/blink/renderer/platform/image-encoders/image_encoder.h"
#include "third_party/blink/renderer/platform/scheduler/public/background_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread.h"
#include "third_party/blink/renderer/platform/scheduler/public/worker_pool.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
// And now, a brief note about clipboard permissions.
......@@ -259,13 +259,13 @@ void ClipboardPromise::OnLoadBufferComplete(DOMArrayBuffer* array_buffer) {
file_reader_.reset();
if (blob_type == kMimeTypeImagePng) {
background_scheduler::PostOnBackgroundThread(
worker_pool::PostTask(
FROM_HERE,
CrossThreadBind(&ClipboardPromise::DecodeImageOnBackgroundThread,
WrapCrossThreadPersistent(this), GetTaskRunner(),
WrapCrossThreadPersistent(array_buffer)));
} else if (blob_type == kMimeTypeTextPlain) {
background_scheduler::PostOnBackgroundThread(
worker_pool::PostTask(
FROM_HERE,
CrossThreadBind(&ClipboardPromise::DecodeTextOnBackgroundThread,
WrapCrossThreadPersistent(this), GetTaskRunner(),
......
......@@ -33,9 +33,9 @@
#include "third_party/blink/renderer/platform/audio/audio_bus.h"
#include "third_party/blink/renderer/platform/audio/audio_file_reader.h"
#include "third_party/blink/renderer/platform/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/scheduler/public/background_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread.h"
#include "third_party/blink/renderer/platform/scheduler/public/worker_pool.h"
namespace blink {
......@@ -55,7 +55,7 @@ void AsyncAudioDecoder::DecodeAsync(
context->GetExecutionContext()->GetTaskRunner(
blink::TaskType::kInternalMedia);
background_scheduler::PostOnBackgroundThread(
worker_pool::PostTask(
FROM_HERE,
CrossThreadBind(&AsyncAudioDecoder::DecodeOnBackgroundThread,
WrapCrossThreadPersistent(audio_data), sample_rate,
......
......@@ -16,9 +16,9 @@
#include "third_party/blink/renderer/platform/bindings/parkable_string_manager.h"
#include "third_party/blink/renderer/platform/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/web_process_memory_dump.h"
#include "third_party/blink/renderer/platform/scheduler/public/background_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread.h"
#include "third_party/blink/renderer/platform/scheduler/public/worker_pool.h"
#include "third_party/blink/renderer/platform/wtf/address_sanitizer.h"
#include "third_party/blink/renderer/platform/wtf/allocator/partitions.h"
#include "third_party/blink/renderer/platform/wtf/thread_specific.h"
......@@ -345,7 +345,7 @@ void ParkableStringImpl::ParkInternal(ParkingMode mode) {
auto params = std::make_unique<CompressionTaskParams>(
this, string_.Bytes(), string_.CharactersSizeInBytes(),
Thread::Current()->GetTaskRunner());
background_scheduler::PostOnBackgroundThread(
worker_pool::PostTask(
FROM_HERE, CrossThreadBind(&ParkableStringImpl::CompressInBackground,
WTF::Passed(std::move(params))));
state_ = State::kParkingInProgress;
......
......@@ -9,7 +9,6 @@ import("//third_party/protobuf/proto_library.gni")
blink_platform_sources("scheduler") {
sources = [
"common/background_scheduler.cc",
"common/cancelable_closure_holder.cc",
"common/cancelable_closure_holder.h",
"common/features.cc",
......@@ -56,6 +55,7 @@ blink_platform_sources("scheduler") {
"common/unprioritized_resource_loading_task_runner_handle.h",
"common/web_resource_loading_task_runner_handle.cc",
"common/web_thread_scheduler.cc",
"common/worker_pool.cc",
"main_thread/auto_advancing_virtual_time_domain.cc",
"main_thread/auto_advancing_virtual_time_domain.h",
"main_thread/deadline_task_runner.cc",
......@@ -101,7 +101,6 @@ blink_platform_sources("scheduler") {
"main_thread/web_render_widget_scheduling_state.cc",
"main_thread/web_scoped_virtual_time_pauser.cc",
"public/aggregated_metric_reporter.h",
"public/background_scheduler.h",
"public/frame_or_worker_scheduler.h",
"public/frame_scheduler.h",
"public/frame_status.h",
......@@ -114,6 +113,7 @@ blink_platform_sources("scheduler") {
"public/thread.h",
"public/thread_cpu_throttler.h",
"public/thread_scheduler.h",
"public/worker_pool.h",
"public/worker_scheduler.h",
"worker/compositor_metrics_helper.cc",
"worker/compositor_metrics_helper.h",
......@@ -178,7 +178,6 @@ jumbo_source_set("unit_tests") {
testonly = true
sources = [
"common/background_scheduler_unittest.cc",
"common/idle_helper_unittest.cc",
"common/idle_memory_reclaimer_unittest.cc",
"common/metrics_helper_unittest.cc",
......@@ -188,6 +187,7 @@ jumbo_source_set("unit_tests") {
"common/throttling/budget_pool_unittest.cc",
"common/throttling/task_queue_throttler_unittest.cc",
"common/tracing_helper_unittest.cc",
"common/worker_pool_unittest.cc",
"main_thread/auto_advancing_virtual_time_domain_unittest.cc",
"main_thread/deadline_task_runner_unittest.cc",
"main_thread/frame_scheduler_impl_unittest.cc",
......
......@@ -151,13 +151,15 @@ as we are focused on making freezing better instead.
## Off-main thread scheduling
If your task doesn’t have to run on the main thread, use
BackgroundScheduler::PostOnBackgroundThread, which uses a thread pool
worker_pool::PostTask, which uses a thread pool
behind the scenes.
Do not create your own dedicated thread if you need ordering for your tasks,
use BackgroundScheduler::CreateBackgroundTaskRunnerWithTraits instead —
use worker_pool::CreateTaskRunnerWithTraits instead —
this creates a sequence (virtual thread which can run tasks in order on
any of the threads in the thread pool).
(Note: this doesn't exist yet because we haven't encountered a use case in Blink
which needs it. If you need one, please task to scheduler-dev@ and we'll add it).
See [threading and tasks](../../../../../docs/threading_and_tasks.md) for
more details.
......
......@@ -2,29 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/platform/scheduler/public/background_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/public/worker_pool.h"
#include "base/location.h"
#include "base/task/post_task.h"
namespace blink {
namespace background_scheduler {
namespace worker_pool {
void PostOnBackgroundThread(const base::Location& location,
CrossThreadClosure closure) {
PostOnBackgroundThreadWithTraits(
location, {base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
std::move(closure));
void PostTask(const base::Location& location, CrossThreadClosure closure) {
PostTaskWithTraits(location,
{base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
std::move(closure));
}
void PostOnBackgroundThreadWithTraits(const base::Location& location,
const base::TaskTraits& traits,
CrossThreadClosure closure) {
void PostTaskWithTraits(const base::Location& location,
const base::TaskTraits& traits,
CrossThreadClosure closure) {
base::PostTaskWithTraits(location, traits,
ConvertToBaseCallback(std::move(closure)));
}
} // namespace background_scheduler
} // namespace worker_pool
} // namespace blink
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/platform/scheduler/public/background_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/public/worker_pool.h"
#include <memory>
#include "base/location.h"
......@@ -24,7 +24,7 @@ void PingPongTask(WaitableEvent* done_event) {
TEST(BackgroundSchedulerTest, RunOnBackgroundThread) {
base::test::ScopedTaskEnvironment scoped_task_environment;
std::unique_ptr<WaitableEvent> done_event = std::make_unique<WaitableEvent>();
background_scheduler::PostOnBackgroundThread(
worker_pool::PostTask(
FROM_HERE,
CrossThreadBind(&PingPongTask, CrossThreadUnretained(done_event.get())));
// Test passes by not hanging on the following wait().
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_SCHEDULER_PUBLIC_BACKGROUND_SCHEDULER_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_SCHEDULER_PUBLIC_BACKGROUND_SCHEDULER_H_
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_SCHEDULER_PUBLIC_WORKER_POOL_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_SCHEDULER_PUBLIC_WORKER_POOL_H_
#include "base/location.h"
#include "base/sequenced_task_runner.h"
......@@ -13,26 +13,29 @@
namespace blink {
namespace background_scheduler {
namespace worker_pool {
// These are a thin wrapper around base::TaskScheduler to accomodate
// Blink's CrossThreadClosure, which only allows background tasks
// (i.e. tasks which are run off the main thread).
// These are a thin wrapper around base::TaskScheduler to ensure that all
// callers use WTF::CrossThreadBind instead of base::Bind to ensure that
// all non-thread-safe objects are copied properly.
//
// Non-background tasks should be posted using another scheduler, e.g.
// FrameShceduler.
PLATFORM_EXPORT void PostOnBackgroundThread(const base::Location&,
CrossThreadClosure);
// All tasks that do not care about which thread they are running on
// (e.g. compressing/uncompressing tasks) use this API.
//
// Tasks that have to run on a specific thread (e.g. main thread, compositor
// thread, dedicated worker thread) should be posted via other means
// (e.g. FrameScheduler for main thread tasks).
PLATFORM_EXPORT void PostTask(const base::Location&, CrossThreadClosure);
PLATFORM_EXPORT void PostOnBackgroundThreadWithTraits(const base::Location&,
const base::TaskTraits&,
CrossThreadClosure);
PLATFORM_EXPORT void PostTaskWithTraits(const base::Location&,
const base::TaskTraits&,
CrossThreadClosure);
// TODO(altimin): Expose CreateBackgroundTaskRunnerWithTraits when the
// TODO(altimin): Expose CreateSequencedTaskRunnerWithTraits when the
// need arises.
} // namespace background_scheduler
} // namespace worker_pool
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_SCHEDULER_PUBLIC_BACKGROUND_SCHEDULER_H_
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_SCHEDULER_PUBLIC_WORKER_POOL_H_
......@@ -236,7 +236,6 @@ _CONFIG = [
'url::.+',
# Nested namespaces under the blink namespace
'background_scheduler::.+',
'canvas_heuristic_parameters::.+',
'compositor_target_property::.+',
'cors::.+',
......@@ -264,11 +263,12 @@ _CONFIG = [
'style_change_extra_data::.+',
'style_change_reason::.+',
'svg_path_parser::.+',
'trace_event::.+',
'touch_action_util::.+',
'trace_event::.+',
'unicode::.+',
'vector_math::.+',
'web_core_test_support::.+',
'worker_pool::.+',
'xpath::.+',
'[a-z_]+_names::.+',
......
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