Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 |
| OLD | NEW |