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

Side by Side Diff: gin/v8_platform.cc

Issue 2610473002: Use TaskScheduler instead of WorkerPool in v8_platform.cc. (Closed)
Patch Set: Blink test environment Created 3 years, 11 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 unified diff | Download patch
« no previous file with comments | « gin/test/v8_test.h ('k') | mojo/edk/js/tests/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gin/public/v8_platform.h" 5 #include "gin/public/v8_platform.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/sys_info.h" 9 #include "base/sys_info.h"
10 #include "base/threading/worker_pool.h" 10 #include "base/task_scheduler/post_task.h"
11 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
12 #include "gin/per_isolate_data.h" 12 #include "gin/per_isolate_data.h"
13 13
14 namespace gin { 14 namespace gin {
15 15
16 namespace { 16 namespace {
17 17
18 base::LazyInstance<V8Platform>::Leaky g_v8_platform = LAZY_INSTANCE_INITIALIZER; 18 base::LazyInstance<V8Platform>::Leaky g_v8_platform = LAZY_INSTANCE_INITIALIZER;
19 19
20 void RunWithLocker(v8::Isolate* isolate, v8::Task* task) { 20 void RunWithLocker(v8::Isolate* isolate, v8::Task* task) {
(...skipping 29 matching lines...) Expand all
50 V8Platform::V8Platform() {} 50 V8Platform::V8Platform() {}
51 51
52 V8Platform::~V8Platform() {} 52 V8Platform::~V8Platform() {}
53 53
54 size_t V8Platform::NumberOfAvailableBackgroundThreads() { 54 size_t V8Platform::NumberOfAvailableBackgroundThreads() {
55 // WorkerPool will currently always create additional threads for posted 55 // WorkerPool will currently always create additional threads for posted
56 // background tasks, unless there are threads sitting idle (on posix). 56 // background tasks, unless there are threads sitting idle (on posix).
57 // Indicate that V8 should create no more than the number of cores available, 57 // Indicate that V8 should create no more than the number of cores available,
58 // reserving one core for the main thread. 58 // reserving one core for the main thread.
59 const size_t available_cores = 59 const size_t available_cores =
60 static_cast<size_t>(base::SysInfo::NumberOfProcessors()); 60 static_cast<size_t>(base::SysInfo::NumberOfProcessors());
jochen (gone - plz use gerrit) 2017/01/24 14:30:12 can you update this to return the max. number of t
fdoray 2017/02/03 17:20:01 Done.
61 if (available_cores > 1) { 61 if (available_cores > 1) {
62 return available_cores - 1; 62 return available_cores - 1;
63 } 63 }
64 return 1; 64 return 1;
65 } 65 }
66 66
67 void V8Platform::CallOnBackgroundThread( 67 void V8Platform::CallOnBackgroundThread(
68 v8::Task* task, 68 v8::Task* task,
69 v8::Platform::ExpectedRuntime expected_runtime) { 69 v8::Platform::ExpectedRuntime expected_runtime) {
70 base::WorkerPool::PostTask( 70 base::PostTaskWithTraits(
71 FROM_HERE, 71 FROM_HERE, base::TaskTraits().WithShutdownBehavior(
72 base::Bind(&v8::Task::Run, base::Owned(task)), 72 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN),
73 expected_runtime == v8::Platform::kLongRunningTask); 73 base::Bind(&v8::Task::Run, base::Owned(task)));
74 } 74 }
75 75
76 void V8Platform::CallOnForegroundThread(v8::Isolate* isolate, v8::Task* task) { 76 void V8Platform::CallOnForegroundThread(v8::Isolate* isolate, v8::Task* task) {
77 PerIsolateData* data = PerIsolateData::From(isolate); 77 PerIsolateData* data = PerIsolateData::From(isolate);
78 if (data->access_mode() == IsolateHolder::kUseLocker) { 78 if (data->access_mode() == IsolateHolder::kUseLocker) {
79 data->task_runner()->PostTask( 79 data->task_runner()->PostTask(
80 FROM_HERE, base::Bind(RunWithLocker, base::Unretained(isolate), 80 FROM_HERE, base::Bind(RunWithLocker, base::Unretained(isolate),
81 base::Owned(task))); 81 base::Owned(task)));
82 } else { 82 } else {
83 data->task_runner()->PostTask( 83 data->task_runner()->PostTask(
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 v8::Platform::TraceStateObserver* observer) { 251 v8::Platform::TraceStateObserver* observer) {
252 g_trace_state_dispatcher.Get().AddObserver(observer); 252 g_trace_state_dispatcher.Get().AddObserver(observer);
253 } 253 }
254 254
255 void V8Platform::RemoveTraceStateObserver( 255 void V8Platform::RemoveTraceStateObserver(
256 v8::Platform::TraceStateObserver* observer) { 256 v8::Platform::TraceStateObserver* observer) {
257 g_trace_state_dispatcher.Get().RemoveObserver(observer); 257 g_trace_state_dispatcher.Get().RemoveObserver(observer);
258 } 258 }
259 259
260 } // namespace gin 260 } // namespace gin
OLDNEW
« no previous file with comments | « gin/test/v8_test.h ('k') | mojo/edk/js/tests/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698