| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "../checks.h" | 33 #include "../checks.h" |
| 34 // TODO(jochen): Why is cpu.h not in platform/? | 34 // TODO(jochen): Why is cpu.h not in platform/? |
| 35 #include "../cpu.h" | 35 #include "../cpu.h" |
| 36 #include "worker-thread.h" | 36 #include "worker-thread.h" |
| 37 | 37 |
| 38 namespace v8 { | 38 namespace v8 { |
| 39 namespace internal { | 39 namespace internal { |
| 40 | 40 |
| 41 | 41 |
| 42 DefaultPlatform::DefaultPlatform() | 42 DefaultPlatform::DefaultPlatform() |
| 43 : initialized_(false) {} | 43 : initialized_(false), thread_pool_size_(0) {} |
| 44 | 44 |
| 45 | 45 |
| 46 DefaultPlatform::~DefaultPlatform() { | 46 DefaultPlatform::~DefaultPlatform() { |
| 47 LockGuard<Mutex> guard(&lock_); | 47 LockGuard<Mutex> guard(&lock_); |
| 48 if (initialized_) { | 48 if (initialized_) { |
| 49 queue_.Terminate(); | 49 queue_.Terminate(); |
| 50 for (std::vector<WorkerThread*>::iterator i = thread_pool_.begin(); | 50 for (std::vector<WorkerThread*>::iterator i = thread_pool_.begin(); |
| 51 i != thread_pool_.end(); ++i) { | 51 i != thread_pool_.end(); ++i) { |
| 52 delete *i; | 52 delete *i; |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| 57 | 57 |
| 58 void DefaultPlatform::SetThreadPoolSize(int thread_pool_size) { | 58 void DefaultPlatform::SetThreadPoolSize(int thread_pool_size) { |
| 59 LockGuard<Mutex> guard(&lock_); | 59 LockGuard<Mutex> guard(&lock_); |
| 60 ASSERT(thread_pool_size >= 0); | 60 ASSERT(thread_pool_size >= 0); |
| 61 if (thread_pool_size < 1) |
| 62 thread_pool_size = CPU::NumberOfProcessorsOnline(); |
| 63 thread_pool_size_ = Max(Min(thread_pool_size, kMaxThreadPoolSize), 1); |
| 64 } |
| 65 |
| 66 |
| 67 void DefaultPlatform::EnsureInitialized() { |
| 68 LockGuard<Mutex> guard(&lock_); |
| 61 if (initialized_) return; | 69 if (initialized_) return; |
| 62 initialized_ = true; | 70 initialized_ = true; |
| 63 if (thread_pool_size < 1) | |
| 64 thread_pool_size = CPU::NumberOfProcessorsOnline(); | |
| 65 thread_pool_size = Max(Min(thread_pool_size, kMaxThreadPoolSize), 1); | |
| 66 | 71 |
| 67 for (int i = 0; i < thread_pool_size; ++i) | 72 for (int i = 0; i < thread_pool_size_; ++i) |
| 68 thread_pool_.push_back(new WorkerThread(&queue_)); | 73 thread_pool_.push_back(new WorkerThread(&queue_)); |
| 69 } | 74 } |
| 70 | 75 |
| 71 void DefaultPlatform::CallOnBackgroundThread(Task *task, | 76 void DefaultPlatform::CallOnBackgroundThread(Task *task, |
| 72 ExpectedRuntime expected_runtime) { | 77 ExpectedRuntime expected_runtime) { |
| 73 #ifdef DEBUG | 78 EnsureInitialized(); |
| 74 { | |
| 75 LockGuard<Mutex> guard(&lock_); | |
| 76 ASSERT(initialized_); | |
| 77 } | |
| 78 #endif | |
| 79 queue_.Append(task); | 79 queue_.Append(task); |
| 80 } | 80 } |
| 81 | 81 |
| 82 | 82 |
| 83 void DefaultPlatform::CallOnForegroundThread(v8::Isolate* isolate, Task* task) { | 83 void DefaultPlatform::CallOnForegroundThread(v8::Isolate* isolate, Task* task) { |
| 84 // TODO(jochen): implement. | 84 // TODO(jochen): implement. |
| 85 task->Run(); | 85 task->Run(); |
| 86 delete task; | 86 delete task; |
| 87 } | 87 } |
| 88 | 88 |
| 89 } } // namespace v8::internal | 89 } } // namespace v8::internal |
| OLD | NEW |