Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(726)

Unified Diff: gin/v8_platform.cc

Issue 2876523002: [reland] Use TaskScheduler instead of WorkerPool in v8_platform.cc. (Closed)
Patch Set: BLOCK_SHUTDOWN Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gin/v8_platform.cc
diff --git a/gin/v8_platform.cc b/gin/v8_platform.cc
index dc887c43c3e0d242f8e599c1e3be96cd35eafda7..1ee4c3a27536b057bde7c09166d8ae9ba6c5e3d7 100644
--- a/gin/v8_platform.cc
+++ b/gin/v8_platform.cc
@@ -4,11 +4,14 @@
#include "gin/public/v8_platform.h"
+#include <algorithm>
+
#include "base/bind.h"
#include "base/debug/stack_trace.h"
#include "base/location.h"
#include "base/sys_info.h"
-#include "base/threading/worker_pool.h"
+#include "base/task_scheduler/post_task.h"
+#include "base/task_scheduler/task_scheduler.h"
#include "base/trace_event/trace_event.h"
#include "gin/per_isolate_data.h"
@@ -16,6 +19,10 @@ namespace gin {
namespace {
+constexpr base::TaskTraits kBackgroundThreadTaskTraits = {
+ base::MayBlock(), base::TaskPriority::USER_VISIBLE,
+ base::TaskShutdownBehavior::BLOCK_SHUTDOWN};
+
base::LazyInstance<V8Platform>::Leaky g_v8_platform = LAZY_INSTANCE_INITIALIZER;
void RunWithLocker(v8::Isolate* isolate, v8::Task* task) {
@@ -58,25 +65,16 @@ V8Platform::V8Platform() {}
V8Platform::~V8Platform() {}
size_t V8Platform::NumberOfAvailableBackgroundThreads() {
- // WorkerPool will currently always create additional threads for posted
- // background tasks, unless there are threads sitting idle (on posix).
- // Indicate that V8 should create no more than the number of cores available,
- // reserving one core for the main thread.
- const size_t available_cores =
- static_cast<size_t>(base::SysInfo::NumberOfProcessors());
- if (available_cores > 1) {
- return available_cores - 1;
- }
- return 1;
+ return std::max(1, base::TaskScheduler::GetInstance()
+ ->GetMaxConcurrentTasksWithTraitsDeprecated(
+ kBackgroundThreadTaskTraits));
}
void V8Platform::CallOnBackgroundThread(
v8::Task* task,
v8::Platform::ExpectedRuntime expected_runtime) {
- base::WorkerPool::PostTask(
- FROM_HERE,
- base::Bind(&v8::Task::Run, base::Owned(task)),
- expected_runtime == v8::Platform::kLongRunningTask);
+ base::PostTaskWithTraits(FROM_HERE, kBackgroundThreadTaskTraits,
+ base::Bind(&v8::Task::Run, base::Owned(task)));
}
void V8Platform::CallOnForegroundThread(v8::Isolate* isolate, v8::Task* task) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698