Chromium Code Reviews| Index: src/libplatform/default-platform.cc |
| diff --git a/src/default-platform.cc b/src/libplatform/default-platform.cc |
| similarity index 60% |
| copy from src/default-platform.cc |
| copy to src/libplatform/default-platform.cc |
| index ef3c4ebd450bbc63ae99b4534a22fa5bd67a2f39..674d311a31a44643eacb398ba4a5e86ecd070c1a 100644 |
| --- a/src/default-platform.cc |
| +++ b/src/libplatform/default-platform.cc |
| @@ -25,24 +25,50 @@ |
| // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| -#include "v8.h" |
| - |
| #include "default-platform.h" |
| +#include <queue> |
| + |
| +// TODO(jochen): We should have our own version of checks.h. |
| +#include "../checks.h" |
| +// TODO(jochen): Why is cpu.h not in platform/? |
| +#include "../cpu.h" |
| +#include "task-queue.h" |
| +#include "worker-thread.h" |
| + |
| namespace v8 { |
| namespace internal { |
| +int DefaultPlatform::thread_pool_size_ = 0; |
| + |
| -DefaultPlatform::DefaultPlatform() {} |
| +DefaultPlatform::DefaultPlatform() : thread_pool_(NULL), queue_(NULL) {} |
| -DefaultPlatform::~DefaultPlatform() {} |
| +DefaultPlatform::~DefaultPlatform() { |
| + if (thread_pool_) { |
| + queue_->Terminate(); |
| + for (int i = 0; i < thread_pool_size_; ++i) { |
| + delete thread_pool_[i]; |
| + } |
| + delete[] thread_pool_; |
| + delete queue_; |
| + } |
| +} |
| + |
| + |
| +// static |
| +void DefaultPlatform::SetThreadPoolSize(int thread_pool_size) { |
| + ASSERT(thread_pool_size >= 0); |
|
Hannes Payer (out of office)
2013/12/09 18:50:51
What about: void DefaultPlatform::SetThreadPoolSiz
jochen (gone - plz use gerrit)
2013/12/09 19:04:31
default parameters are forbidden by the coding sty
Hannes Payer (out of office)
2013/12/11 12:07:27
OK, fine with me.
|
| + // TODO(jochen): If this wasn't a static member, we should |
| + // ASSERT(!thread_pool_); |
| + thread_pool_size_ = thread_pool_size; |
| +} |
| void DefaultPlatform::CallOnBackgroundThread(Task *task, |
| ExpectedRuntime expected_runtime) { |
| - // TODO(jochen): implement. |
| - task->Run(); |
| - delete task; |
| + EnsureThreadPoolStarted(); |
| + queue_->Append(task); |
| } |
| @@ -53,4 +79,17 @@ void DefaultPlatform::CallOnForegroundThread(v8::Isolate* isolate, Task* task) { |
| } |
| +void DefaultPlatform::EnsureThreadPoolStarted() { |
| + if (thread_pool_) return; |
| + queue_ = new TaskQueue; |
| + if (thread_pool_size_ < 1) |
| + thread_pool_size_ = CPU::NumberOfProcessorsOnline(); |
| + thread_pool_size_ = Max(Min(thread_pool_size_, kMaxThreadPoolSize), 1); |
|
Hannes Payer (out of office)
2013/12/09 18:50:51
I think this should be handled by SetThreadPoolSiz
jochen (gone - plz use gerrit)
2013/12/09 19:04:31
I would have to duplicate this here for the case t
Hannes Payer (out of office)
2013/12/11 12:07:27
OK, you could also invoke SetThreadPool size from
|
| + |
| + thread_pool_ = new WorkerThread*[thread_pool_size_]; |
| + |
| + for (int i = 0; i < thread_pool_size_; ++i) |
| + thread_pool_[i] = new WorkerThread(queue_); |
| +} |
| + |
| } } // namespace v8::internal |