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/threading/worker_pool.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) { | |
| 21 v8::Locker lock(isolate); | |
| 22 task->Run(); | |
| 23 } | |
| 24 | |
| 20 } // namespace | 25 } // namespace |
| 21 | 26 |
| 22 // static | 27 // static |
| 23 V8Platform* V8Platform::Get() { return g_v8_platform.Pointer(); } | 28 V8Platform* V8Platform::Get() { return g_v8_platform.Pointer(); } |
| 24 | 29 |
| 25 V8Platform::V8Platform() {} | 30 V8Platform::V8Platform() {} |
| 26 | 31 |
| 27 V8Platform::~V8Platform() {} | 32 V8Platform::~V8Platform() {} |
| 28 | 33 |
| 29 size_t V8Platform::NumberOfAvailableBackgroundThreads() { | 34 size_t V8Platform::NumberOfAvailableBackgroundThreads() { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 42 void V8Platform::CallOnBackgroundThread( | 47 void V8Platform::CallOnBackgroundThread( |
| 43 v8::Task* task, | 48 v8::Task* task, |
| 44 v8::Platform::ExpectedRuntime expected_runtime) { | 49 v8::Platform::ExpectedRuntime expected_runtime) { |
| 45 base::WorkerPool::PostTask( | 50 base::WorkerPool::PostTask( |
| 46 FROM_HERE, | 51 FROM_HERE, |
| 47 base::Bind(&v8::Task::Run, base::Owned(task)), | 52 base::Bind(&v8::Task::Run, base::Owned(task)), |
| 48 expected_runtime == v8::Platform::kLongRunningTask); | 53 expected_runtime == v8::Platform::kLongRunningTask); |
| 49 } | 54 } |
| 50 | 55 |
| 51 void V8Platform::CallOnForegroundThread(v8::Isolate* isolate, v8::Task* task) { | 56 void V8Platform::CallOnForegroundThread(v8::Isolate* isolate, v8::Task* task) { |
| 52 PerIsolateData::From(isolate)->task_runner()->PostTask( | 57 PerIsolateData* data = PerIsolateData::From(isolate); |
|
ulan
2016/11/04 14:28:30
The same change should apply to other Call*OnForeg
| |
| 53 FROM_HERE, base::Bind(&v8::Task::Run, base::Owned(task))); | 58 if (data->access_mode() == IsolateHolder::kUseLocker) { |
| 59 data->task_runner()->PostTask( | |
| 60 FROM_HERE, base::Bind(RunWithLocker, base::Unretained(isolate), | |
| 61 base::Owned(task))); | |
| 62 } else { | |
| 63 data->task_runner()->PostTask( | |
| 64 FROM_HERE, base::Bind(&v8::Task::Run, base::Owned(task))); | |
| 65 } | |
| 54 } | 66 } |
| 55 | 67 |
| 56 void V8Platform::CallDelayedOnForegroundThread(v8::Isolate* isolate, | 68 void V8Platform::CallDelayedOnForegroundThread(v8::Isolate* isolate, |
| 57 v8::Task* task, | 69 v8::Task* task, |
| 58 double delay_in_seconds) { | 70 double delay_in_seconds) { |
| 59 PerIsolateData::From(isolate)->task_runner()->PostDelayedTask( | 71 PerIsolateData::From(isolate)->task_runner()->PostDelayedTask( |
| 60 FROM_HERE, base::Bind(&v8::Task::Run, base::Owned(task)), | 72 FROM_HERE, base::Bind(&v8::Task::Run, base::Owned(task)), |
| 61 base::TimeDelta::FromSecondsD(delay_in_seconds)); | 73 base::TimeDelta::FromSecondsD(delay_in_seconds)); |
| 62 } | 74 } |
| 63 | 75 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 v8::Platform::TraceStateObserver* observer) { | 217 v8::Platform::TraceStateObserver* observer) { |
| 206 g_trace_state_dispatcher.Get().AddObserver(observer); | 218 g_trace_state_dispatcher.Get().AddObserver(observer); |
| 207 } | 219 } |
| 208 | 220 |
| 209 void V8Platform::RemoveTraceStateObserver( | 221 void V8Platform::RemoveTraceStateObserver( |
| 210 v8::Platform::TraceStateObserver* observer) { | 222 v8::Platform::TraceStateObserver* observer) { |
| 211 g_trace_state_dispatcher.Get().RemoveObserver(observer); | 223 g_trace_state_dispatcher.Get().RemoveObserver(observer); |
| 212 } | 224 } |
| 213 | 225 |
| 214 } // namespace gin | 226 } // namespace gin |
| OLD | NEW |