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 23 matching lines...) Expand all Loading... |
34 | 34 |
35 | 35 |
36 DefaultPlatform::DefaultPlatform() | 36 DefaultPlatform::DefaultPlatform() |
37 : initialized_(false), thread_pool_size_(0) {} | 37 : initialized_(false), thread_pool_size_(0) {} |
38 | 38 |
39 | 39 |
40 DefaultPlatform::~DefaultPlatform() { | 40 DefaultPlatform::~DefaultPlatform() { |
41 base::LockGuard<base::Mutex> guard(&lock_); | 41 base::LockGuard<base::Mutex> guard(&lock_); |
42 queue_.Terminate(); | 42 queue_.Terminate(); |
43 if (initialized_) { | 43 if (initialized_) { |
44 for (std::vector<WorkerThread*>::iterator i = thread_pool_.begin(); | 44 for (auto i = thread_pool_.begin(); i != thread_pool_.end(); ++i) { |
45 i != thread_pool_.end(); ++i) { | |
46 delete *i; | 45 delete *i; |
47 } | 46 } |
48 } | 47 } |
49 for (std::map<v8::Isolate*, std::queue<Task*> >::iterator i = | 48 for (auto i = main_thread_queue_.begin(); i != main_thread_queue_.end(); |
50 main_thread_queue_.begin(); | 49 ++i) { |
51 i != main_thread_queue_.end(); ++i) { | |
52 while (!i->second.empty()) { | 50 while (!i->second.empty()) { |
53 delete i->second.front(); | 51 delete i->second.front(); |
54 i->second.pop(); | 52 i->second.pop(); |
55 } | 53 } |
56 } | 54 } |
| 55 for (auto i = main_thread_delayed_queue_.begin(); |
| 56 i != main_thread_delayed_queue_.end(); ++i) { |
| 57 while (!i->second.empty()) { |
| 58 delete i->second.top().second; |
| 59 i->second.pop(); |
| 60 } |
| 61 } |
57 } | 62 } |
58 | 63 |
59 | 64 |
60 void DefaultPlatform::SetThreadPoolSize(int thread_pool_size) { | 65 void DefaultPlatform::SetThreadPoolSize(int thread_pool_size) { |
61 base::LockGuard<base::Mutex> guard(&lock_); | 66 base::LockGuard<base::Mutex> guard(&lock_); |
62 DCHECK(thread_pool_size >= 0); | 67 DCHECK(thread_pool_size >= 0); |
63 if (thread_pool_size < 1) { | 68 if (thread_pool_size < 1) { |
64 thread_pool_size = base::SysInfo::NumberOfProcessors(); | 69 thread_pool_size = base::SysInfo::NumberOfProcessors(); |
65 } | 70 } |
66 thread_pool_size_ = | 71 thread_pool_size_ = |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 double deadline = MonotonicallyIncreasingTime() + delay_in_seconds; | 152 double deadline = MonotonicallyIncreasingTime() + delay_in_seconds; |
148 main_thread_delayed_queue_[isolate].push(std::make_pair(deadline, task)); | 153 main_thread_delayed_queue_[isolate].push(std::make_pair(deadline, task)); |
149 } | 154 } |
150 | 155 |
151 | 156 |
152 double DefaultPlatform::MonotonicallyIncreasingTime() { | 157 double DefaultPlatform::MonotonicallyIncreasingTime() { |
153 return base::TimeTicks::HighResolutionNow().ToInternalValue() / | 158 return base::TimeTicks::HighResolutionNow().ToInternalValue() / |
154 static_cast<double>(base::Time::kMicrosecondsPerSecond); | 159 static_cast<double>(base::Time::kMicrosecondsPerSecond); |
155 } | 160 } |
156 } } // namespace v8::platform | 161 } } // namespace v8::platform |
OLD | NEW |