Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: src/libplatform/default-platform.cc

Issue 1221083004: Fix memory-leak in default platform implementation of delayed tasks. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/unittests/libplatform/default-platform-unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « no previous file | test/unittests/libplatform/default-platform-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698