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
3 // found in the LICENSE file.
5 #include "default-platform.h"
10 // TODO(jochen): We should have our own version of checks.h.
11 #include "../checks.h"
12 // TODO(jochen): Why is cpu.h not in platform/?
14 #include "worker-thread.h"
20 const int DefaultPlatform::kMaxThreadPoolSize = 4;
23 DefaultPlatform::DefaultPlatform()
24 : initialized_(false), thread_pool_size_(0) {}
27 DefaultPlatform::~DefaultPlatform() {
28 LockGuard<Mutex> guard(&lock_);
31 for (std::vector<WorkerThread*>::iterator i = thread_pool_.begin();
32 i != thread_pool_.end(); ++i) {
39 void DefaultPlatform::SetThreadPoolSize(int thread_pool_size) {
40 LockGuard<Mutex> guard(&lock_);
41 ASSERT(thread_pool_size >= 0);
42 if (thread_pool_size < 1)
43 thread_pool_size = CPU::NumberOfProcessorsOnline();
45 std::max(std::min(thread_pool_size, kMaxThreadPoolSize), 1);
49 void DefaultPlatform::EnsureInitialized() {
50 LockGuard<Mutex> guard(&lock_);
51 if (initialized_) return;
54 for (int i = 0; i < thread_pool_size_; ++i)
55 thread_pool_.push_back(new WorkerThread(&queue_));
58 void DefaultPlatform::CallOnBackgroundThread(Task *task,
59 ExpectedRuntime expected_runtime) {
65 void DefaultPlatform::CallOnForegroundThread(v8::Isolate* isolate, Task* task) {
66 // TODO(jochen): implement.
71 } } // namespace v8::internal