Reviewers: Hannes Payer,
Description:
Lazily initialize thread pool to avoid allocating all the threads during
startup
[email protected]
BUG=none
LOG=n
Please review this at https://codereview.chromium.org/98123004/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+14, -11 lines):
M src/libplatform/default-platform.h
M src/libplatform/default-platform.cc
Index: src/libplatform/default-platform.cc
diff --git a/src/libplatform/default-platform.cc
b/src/libplatform/default-platform.cc
index
f05dc1107a0d5f1e7bbac104b91f703715587ccb..72e6002c3f939551c6d2de7be125872d97c4acd9
100644
--- a/src/libplatform/default-platform.cc
+++ b/src/libplatform/default-platform.cc
@@ -40,7 +40,7 @@ namespace internal {
DefaultPlatform::DefaultPlatform()
- : initialized_(false) {}
+ : initialized_(false), thread_pool_size_(0) {}
DefaultPlatform::~DefaultPlatform() {
@@ -58,24 +58,24 @@ DefaultPlatform::~DefaultPlatform() {
void DefaultPlatform::SetThreadPoolSize(int thread_pool_size) {
LockGuard<Mutex> guard(&lock_);
ASSERT(thread_pool_size >= 0);
- if (initialized_) return;
- initialized_ = true;
if (thread_pool_size < 1)
thread_pool_size = CPU::NumberOfProcessorsOnline();
- thread_pool_size = Max(Min(thread_pool_size, kMaxThreadPoolSize), 1);
+ thread_pool_size_ = Max(Min(thread_pool_size, kMaxThreadPoolSize), 1);
+}
- for (int i = 0; i < thread_pool_size; ++i)
+
+void DefaultPlatform::EnsureInitialized() {
+ LockGuard<Mutex> guard(&lock_);
+ if (initialized_) return;
+ initialized_ = true;
+
+ for (int i = 0; i < thread_pool_size_; ++i)
thread_pool_.push_back(new WorkerThread(&queue_));
}
void DefaultPlatform::CallOnBackgroundThread(Task *task,
ExpectedRuntime
expected_runtime) {
-#ifdef DEBUG
- {
- LockGuard<Mutex> guard(&lock_);
- ASSERT(initialized_);
- }
-#endif
+ EnsureInitialized();
queue_.Append(task);
}
Index: src/libplatform/default-platform.h
diff --git a/src/libplatform/default-platform.h
b/src/libplatform/default-platform.h
index
72e8869992ffb7f40ce7a206aab9e6712daf3334..877b3a63e7b23e5882face165b5f393e27867800
100644
--- a/src/libplatform/default-platform.h
+++ b/src/libplatform/default-platform.h
@@ -59,8 +59,11 @@ class DefaultPlatform : public Platform {
private:
static const int kMaxThreadPoolSize = 4;
+ void EnsureInitialized();
+
Mutex lock_;
bool initialized_;
+ int thread_pool_size_;
std::vector<WorkerThread*> thread_pool_;
TaskQueue queue_;
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.