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 12 matching lines...) Expand all Loading... | |
23 platform->EnsureInitialized(); | 23 platform->EnsureInitialized(); |
24 return platform; | 24 return platform; |
25 } | 25 } |
26 | 26 |
27 | 27 |
28 bool PumpMessageLoop(v8::Platform* platform, v8::Isolate* isolate) { | 28 bool PumpMessageLoop(v8::Platform* platform, v8::Isolate* isolate) { |
29 return reinterpret_cast<DefaultPlatform*>(platform)->PumpMessageLoop(isolate); | 29 return reinterpret_cast<DefaultPlatform*>(platform)->PumpMessageLoop(isolate); |
30 } | 30 } |
31 | 31 |
32 | 32 |
33 const int DefaultPlatform::kMaxThreadPoolSize = 4; | 33 const int DefaultPlatform::kDefaultThreadPoolSize = 4; |
34 | 34 |
35 | 35 |
36 DefaultPlatform::DefaultPlatform() | 36 DefaultPlatform::DefaultPlatform() |
37 : initialized_(false), thread_pool_size_(0) {} | 37 : initialized_(false), |
38 max_thread_pool_size_(base::SysInfo::NumberOfProcessors()), | |
39 thread_pool_size_(kDefaultThreadPoolSize) {} | |
38 | 40 |
39 | 41 |
40 DefaultPlatform::~DefaultPlatform() { | 42 DefaultPlatform::~DefaultPlatform() { |
41 base::LockGuard<base::Mutex> guard(&lock_); | 43 base::LockGuard<base::Mutex> guard(&lock_); |
42 queue_.Terminate(); | 44 queue_.Terminate(); |
43 if (initialized_) { | 45 if (initialized_) { |
44 for (auto i = thread_pool_.begin(); i != thread_pool_.end(); ++i) { | 46 for (auto i = thread_pool_.begin(); i != thread_pool_.end(); ++i) { |
45 delete *i; | 47 delete *i; |
46 } | 48 } |
47 } | 49 } |
(...skipping 11 matching lines...) Expand all Loading... | |
59 i->second.pop(); | 61 i->second.pop(); |
60 } | 62 } |
61 } | 63 } |
62 } | 64 } |
63 | 65 |
64 | 66 |
65 void DefaultPlatform::SetThreadPoolSize(int thread_pool_size) { | 67 void DefaultPlatform::SetThreadPoolSize(int thread_pool_size) { |
66 base::LockGuard<base::Mutex> guard(&lock_); | 68 base::LockGuard<base::Mutex> guard(&lock_); |
67 DCHECK(thread_pool_size >= 0); | 69 DCHECK(thread_pool_size >= 0); |
68 if (thread_pool_size < 1) { | 70 if (thread_pool_size < 1) { |
69 thread_pool_size = base::SysInfo::NumberOfProcessors(); | 71 thread_pool_size = kDefaultThreadPoolSize; |
70 } | 72 } |
71 thread_pool_size_ = | 73 thread_pool_size_ = |
72 std::max(std::min(thread_pool_size, kMaxThreadPoolSize), 1); | 74 std::max(std::min(thread_pool_size, max_thread_pool_size_), 1); |
jochen (gone - plz use gerrit)
2016/01/08 14:46:18
any reason you store this in a member instead of j
| |
73 } | 75 } |
74 | 76 |
75 | 77 |
76 void DefaultPlatform::EnsureInitialized() { | 78 void DefaultPlatform::EnsureInitialized() { |
77 base::LockGuard<base::Mutex> guard(&lock_); | 79 base::LockGuard<base::Mutex> guard(&lock_); |
78 if (initialized_) return; | 80 if (initialized_) return; |
79 initialized_ = true; | 81 initialized_ = true; |
80 | 82 |
81 for (int i = 0; i < thread_pool_size_; ++i) | 83 for (int i = 0; i < thread_pool_size_; ++i) |
82 thread_pool_.push_back(new WorkerThread(&queue_)); | 84 thread_pool_.push_back(new WorkerThread(&queue_)); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 } | 190 } |
189 | 191 |
190 | 192 |
191 const char* DefaultPlatform::GetCategoryGroupName( | 193 const char* DefaultPlatform::GetCategoryGroupName( |
192 const uint8_t* category_enabled_flag) { | 194 const uint8_t* category_enabled_flag) { |
193 static const char dummy[] = "dummy"; | 195 static const char dummy[] = "dummy"; |
194 return dummy; | 196 return dummy; |
195 } | 197 } |
196 } // namespace platform | 198 } // namespace platform |
197 } // namespace v8 | 199 } // namespace v8 |
OLD | NEW |