| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project 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 "src/libplatform/default-platform.h" | 5 #include "src/libplatform/default-platform.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <queue> | 8 #include <queue> |
| 9 | 9 |
| 10 #include "src/base/logging.h" | 10 #include "src/base/logging.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 void SetTracingController( | 32 void SetTracingController( |
| 33 v8::Platform* platform, | 33 v8::Platform* platform, |
| 34 v8::platform::tracing::TracingController* tracing_controller) { | 34 v8::platform::tracing::TracingController* tracing_controller) { |
| 35 return reinterpret_cast<DefaultPlatform*>(platform)->SetTracingController( | 35 return reinterpret_cast<DefaultPlatform*>(platform)->SetTracingController( |
| 36 tracing_controller); | 36 tracing_controller); |
| 37 } | 37 } |
| 38 | 38 |
| 39 const int DefaultPlatform::kMaxThreadPoolSize = 8; | 39 const int DefaultPlatform::kMaxThreadPoolSize = 8; |
| 40 | 40 |
| 41 DefaultPlatform::DefaultPlatform() | 41 DefaultPlatform::DefaultPlatform() |
| 42 : initialized_(false), thread_pool_size_(0), tracing_controller_(NULL) {} | 42 : initialized_(false), thread_pool_size_(0) {} |
| 43 | 43 |
| 44 DefaultPlatform::~DefaultPlatform() { | 44 DefaultPlatform::~DefaultPlatform() { |
| 45 if (tracing_controller_) { |
| 46 tracing_controller_->StopTracing(); |
| 47 tracing_controller_.reset(); |
| 48 } |
| 49 |
| 45 base::LockGuard<base::Mutex> guard(&lock_); | 50 base::LockGuard<base::Mutex> guard(&lock_); |
| 46 queue_.Terminate(); | 51 queue_.Terminate(); |
| 47 if (initialized_) { | 52 if (initialized_) { |
| 48 for (auto i = thread_pool_.begin(); i != thread_pool_.end(); ++i) { | 53 for (auto i = thread_pool_.begin(); i != thread_pool_.end(); ++i) { |
| 49 delete *i; | 54 delete *i; |
| 50 } | 55 } |
| 51 } | 56 } |
| 52 for (auto i = main_thread_queue_.begin(); i != main_thread_queue_.end(); | 57 for (auto i = main_thread_queue_.begin(); i != main_thread_queue_.end(); |
| 53 ++i) { | 58 ++i) { |
| 54 while (!i->second.empty()) { | 59 while (!i->second.empty()) { |
| 55 delete i->second.front(); | 60 delete i->second.front(); |
| 56 i->second.pop(); | 61 i->second.pop(); |
| 57 } | 62 } |
| 58 } | 63 } |
| 59 for (auto i = main_thread_delayed_queue_.begin(); | 64 for (auto i = main_thread_delayed_queue_.begin(); |
| 60 i != main_thread_delayed_queue_.end(); ++i) { | 65 i != main_thread_delayed_queue_.end(); ++i) { |
| 61 while (!i->second.empty()) { | 66 while (!i->second.empty()) { |
| 62 delete i->second.top().second; | 67 delete i->second.top().second; |
| 63 i->second.pop(); | 68 i->second.pop(); |
| 64 } | 69 } |
| 65 } | 70 } |
| 66 | |
| 67 if (tracing_controller_) { | |
| 68 tracing_controller_->StopTracing(); | |
| 69 delete tracing_controller_; | |
| 70 } | |
| 71 } | 71 } |
| 72 | 72 |
| 73 | 73 |
| 74 void DefaultPlatform::SetThreadPoolSize(int thread_pool_size) { | 74 void DefaultPlatform::SetThreadPoolSize(int thread_pool_size) { |
| 75 base::LockGuard<base::Mutex> guard(&lock_); | 75 base::LockGuard<base::Mutex> guard(&lock_); |
| 76 DCHECK(thread_pool_size >= 0); | 76 DCHECK(thread_pool_size >= 0); |
| 77 if (thread_pool_size < 1) { | 77 if (thread_pool_size < 1) { |
| 78 thread_pool_size = base::SysInfo::NumberOfProcessors() - 1; | 78 thread_pool_size = base::SysInfo::NumberOfProcessors() - 1; |
| 79 } | 79 } |
| 80 thread_pool_size_ = | 80 thread_pool_size_ = |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 211 |
| 212 | 212 |
| 213 const char* DefaultPlatform::GetCategoryGroupName( | 213 const char* DefaultPlatform::GetCategoryGroupName( |
| 214 const uint8_t* category_enabled_flag) { | 214 const uint8_t* category_enabled_flag) { |
| 215 static const char dummy[] = "dummy"; | 215 static const char dummy[] = "dummy"; |
| 216 return dummy; | 216 return dummy; |
| 217 } | 217 } |
| 218 | 218 |
| 219 void DefaultPlatform::SetTracingController( | 219 void DefaultPlatform::SetTracingController( |
| 220 tracing::TracingController* tracing_controller) { | 220 tracing::TracingController* tracing_controller) { |
| 221 tracing_controller_ = tracing_controller; | 221 tracing_controller_.reset(tracing_controller); |
| 222 } | 222 } |
| 223 | 223 |
| 224 size_t DefaultPlatform::NumberOfAvailableBackgroundThreads() { | 224 size_t DefaultPlatform::NumberOfAvailableBackgroundThreads() { |
| 225 return static_cast<size_t>(thread_pool_size_); | 225 return static_cast<size_t>(thread_pool_size_); |
| 226 } | 226 } |
| 227 | 227 |
| 228 void DefaultPlatform::AddTraceStateObserver(TraceStateObserver* observer) { |
| 229 if (!tracing_controller_) return; |
| 230 tracing_controller_->AddTraceStateObserver(observer); |
| 231 } |
| 232 |
| 233 void DefaultPlatform::RemoveTraceStateObserver(TraceStateObserver* observer) { |
| 234 if (!tracing_controller_) return; |
| 235 tracing_controller_->RemoveTraceStateObserver(observer); |
| 236 } |
| 237 |
| 228 } // namespace platform | 238 } // namespace platform |
| 229 } // namespace v8 | 239 } // namespace v8 |
| OLD | NEW |