| Index: src/libplatform/default-platform.cc
|
| diff --git a/src/libplatform/default-platform.cc b/src/libplatform/default-platform.cc
|
| index 9a2c30dcdefa769913205aac21ab68352efaf8e9..a05ec7dedb102525ba6c21c3d6d79bada6a6d793 100644
|
| --- a/src/libplatform/default-platform.cc
|
| +++ b/src/libplatform/default-platform.cc
|
| @@ -23,6 +23,11 @@ v8::Platform* CreateDefaultPlatform(int thread_pool_size) {
|
| }
|
|
|
|
|
| +bool PumpMessageLoop(v8::Platform* platform, v8::Isolate* isolate) {
|
| + return reinterpret_cast<DefaultPlatform*>(platform)->PumpMessageLoop(isolate);
|
| +}
|
| +
|
| +
|
| const int DefaultPlatform::kMaxThreadPoolSize = 4;
|
|
|
|
|
| @@ -39,6 +44,14 @@ DefaultPlatform::~DefaultPlatform() {
|
| delete *i;
|
| }
|
| }
|
| + for (std::map<v8::Isolate*, std::queue<Task*> >::iterator i =
|
| + main_thread_queue_.begin();
|
| + i != main_thread_queue_.end(); ++i) {
|
| + while (!i->second.empty()) {
|
| + delete i->second.front();
|
| + i->second.pop();
|
| + }
|
| + }
|
| }
|
|
|
|
|
| @@ -61,6 +74,24 @@ void DefaultPlatform::EnsureInitialized() {
|
| thread_pool_.push_back(new WorkerThread(&queue_));
|
| }
|
|
|
| +
|
| +bool DefaultPlatform::PumpMessageLoop(v8::Isolate* isolate) {
|
| + Task* task = NULL;
|
| + {
|
| + base::LockGuard<base::Mutex> guard(&lock_);
|
| + std::map<v8::Isolate*, std::queue<Task*> >::iterator it =
|
| + main_thread_queue_.find(isolate);
|
| + if (it == main_thread_queue_.end() || it->second.empty()) {
|
| + return false;
|
| + }
|
| + task = it->second.front();
|
| + it->second.pop();
|
| + }
|
| + task->Run();
|
| + delete task;
|
| + return true;
|
| +}
|
| +
|
| void DefaultPlatform::CallOnBackgroundThread(Task *task,
|
| ExpectedRuntime expected_runtime) {
|
| EnsureInitialized();
|
| @@ -69,9 +100,8 @@ void DefaultPlatform::CallOnBackgroundThread(Task *task,
|
|
|
|
|
| void DefaultPlatform::CallOnForegroundThread(v8::Isolate* isolate, Task* task) {
|
| - // TODO(jochen): implement.
|
| - task->Run();
|
| - delete task;
|
| + base::LockGuard<base::Mutex> guard(&lock_);
|
| + main_thread_queue_[isolate].push(task);
|
| }
|
|
|
| } } // namespace v8::platform
|
|
|