| Index: src/libplatform/default-platform.cc
|
| diff --git a/src/default-platform.cc b/src/libplatform/default-platform.cc
|
| similarity index 64%
|
| rename from src/default-platform.cc
|
| rename to src/libplatform/default-platform.cc
|
| index ef3c4ebd450bbc63ae99b4534a22fa5bd67a2f39..f05dc1107a0d5f1e7bbac104b91f703715587ccb 100644
|
| --- a/src/default-platform.cc
|
| +++ b/src/libplatform/default-platform.cc
|
| @@ -25,24 +25,58 @@
|
| // (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 "worker-thread.h"
|
| +
|
| namespace v8 {
|
| namespace internal {
|
|
|
|
|
| -DefaultPlatform::DefaultPlatform() {}
|
| +DefaultPlatform::DefaultPlatform()
|
| + : initialized_(false) {}
|
| +
|
| +
|
| +DefaultPlatform::~DefaultPlatform() {
|
| + LockGuard<Mutex> guard(&lock_);
|
| + if (initialized_) {
|
| + queue_.Terminate();
|
| + for (std::vector<WorkerThread*>::iterator i = thread_pool_.begin();
|
| + i != thread_pool_.end(); ++i) {
|
| + delete *i;
|
| + }
|
| + }
|
| +}
|
| +
|
|
|
| +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);
|
|
|
| -DefaultPlatform::~DefaultPlatform() {}
|
| + for (int i = 0; i < thread_pool_size; ++i)
|
| + thread_pool_.push_back(new WorkerThread(&queue_));
|
| +}
|
|
|
| void DefaultPlatform::CallOnBackgroundThread(Task *task,
|
| ExpectedRuntime expected_runtime) {
|
| - // TODO(jochen): implement.
|
| - task->Run();
|
| - delete task;
|
| +#ifdef DEBUG
|
| + {
|
| + LockGuard<Mutex> guard(&lock_);
|
| + ASSERT(initialized_);
|
| + }
|
| +#endif
|
| + queue_.Append(task);
|
| }
|
|
|
|
|
| @@ -52,5 +86,4 @@ void DefaultPlatform::CallOnForegroundThread(v8::Isolate* isolate, Task* task) {
|
| delete task;
|
| }
|
|
|
| -
|
| } } // namespace v8::internal
|
|
|