summaryrefslogtreecommitdiff
path: root/deps/v8/src/libplatform
diff options
context:
space:
mode:
authorAli Ijaz Sheikh <ofrobots@google.com>2015-08-23 06:09:40 -0700
committerRod Vagg <rod@vagg.org>2015-09-06 21:38:01 +1000
commit9fddd83cf9adf505bce2e2373881df0c4d41b261 (patch)
tree4272ce14c10fea496af2e78fc6debb187d613451 /deps/v8/src/libplatform
parent46b7d151674d138e7ea4342d5f3ada1208b87ff2 (diff)
downloadnode-new-9fddd83cf9adf505bce2e2373881df0c4d41b261.tar.gz
deps: upgrade V8 to 4.5.103.24
Upgrade to the latest branch-head for V8 4.5. For the full commit log see https://github.com/v8/v8-git-mirror/commits/4.5.103.24 PR-URL: https://github.com/nodejs/node/pull/2509 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'deps/v8/src/libplatform')
-rw-r--r--deps/v8/src/libplatform/default-platform.cc67
-rw-r--r--deps/v8/src/libplatform/default-platform.h12
2 files changed, 69 insertions, 10 deletions
diff --git a/deps/v8/src/libplatform/default-platform.cc b/deps/v8/src/libplatform/default-platform.cc
index 1ac52f919f..b41c5852a8 100644
--- a/deps/v8/src/libplatform/default-platform.cc
+++ b/deps/v8/src/libplatform/default-platform.cc
@@ -41,19 +41,24 @@ DefaultPlatform::~DefaultPlatform() {
base::LockGuard<base::Mutex> guard(&lock_);
queue_.Terminate();
if (initialized_) {
- for (std::vector<WorkerThread*>::iterator i = thread_pool_.begin();
- i != thread_pool_.end(); ++i) {
+ for (auto i = thread_pool_.begin(); i != thread_pool_.end(); ++i) {
delete *i;
}
}
- for (std::map<v8::Isolate*, std::queue<Task*> >::iterator i =
- main_thread_queue_.begin();
- i != main_thread_queue_.end(); ++i) {
+ for (auto i = main_thread_queue_.begin(); i != main_thread_queue_.end();
+ ++i) {
while (!i->second.empty()) {
delete i->second.front();
i->second.pop();
}
}
+ for (auto i = main_thread_delayed_queue_.begin();
+ i != main_thread_delayed_queue_.end(); ++i) {
+ while (!i->second.empty()) {
+ delete i->second.top().second;
+ i->second.pop();
+ }
+ }
}
@@ -78,23 +83,56 @@ void DefaultPlatform::EnsureInitialized() {
}
+Task* DefaultPlatform::PopTaskInMainThreadQueue(v8::Isolate* isolate) {
+ auto it = main_thread_queue_.find(isolate);
+ if (it == main_thread_queue_.end() || it->second.empty()) {
+ return NULL;
+ }
+ Task* task = it->second.front();
+ it->second.pop();
+ return task;
+}
+
+
+Task* DefaultPlatform::PopTaskInMainThreadDelayedQueue(v8::Isolate* isolate) {
+ auto it = main_thread_delayed_queue_.find(isolate);
+ if (it == main_thread_delayed_queue_.end() || it->second.empty()) {
+ return NULL;
+ }
+ double now = MonotonicallyIncreasingTime();
+ std::pair<double, Task*> deadline_and_task = it->second.top();
+ if (deadline_and_task.first > now) {
+ return NULL;
+ }
+ it->second.pop();
+ return deadline_and_task.second;
+}
+
+
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()) {
+
+ // Move delayed tasks that hit their deadline to the main queue.
+ task = PopTaskInMainThreadDelayedQueue(isolate);
+ while (task != NULL) {
+ main_thread_queue_[isolate].push(task);
+ task = PopTaskInMainThreadDelayedQueue(isolate);
+ }
+
+ task = PopTaskInMainThreadQueue(isolate);
+
+ if (task == NULL) {
return false;
}
- task = it->second.front();
- it->second.pop();
}
task->Run();
delete task;
return true;
}
+
void DefaultPlatform::CallOnBackgroundThread(Task *task,
ExpectedRuntime expected_runtime) {
EnsureInitialized();
@@ -108,6 +146,15 @@ void DefaultPlatform::CallOnForegroundThread(v8::Isolate* isolate, Task* task) {
}
+void DefaultPlatform::CallDelayedOnForegroundThread(Isolate* isolate,
+ Task* task,
+ double delay_in_seconds) {
+ base::LockGuard<base::Mutex> guard(&lock_);
+ double deadline = MonotonicallyIncreasingTime() + delay_in_seconds;
+ main_thread_delayed_queue_[isolate].push(std::make_pair(deadline, task));
+}
+
+
double DefaultPlatform::MonotonicallyIncreasingTime() {
return base::TimeTicks::HighResolutionNow().ToInternalValue() /
static_cast<double>(base::Time::kMicrosecondsPerSecond);
diff --git a/deps/v8/src/libplatform/default-platform.h b/deps/v8/src/libplatform/default-platform.h
index 72b4d91aa8..fba5803f40 100644
--- a/deps/v8/src/libplatform/default-platform.h
+++ b/deps/v8/src/libplatform/default-platform.h
@@ -5,6 +5,7 @@
#ifndef V8_LIBPLATFORM_DEFAULT_PLATFORM_H_
#define V8_LIBPLATFORM_DEFAULT_PLATFORM_H_
+#include <functional>
#include <map>
#include <queue>
#include <vector>
@@ -37,11 +38,16 @@ class DefaultPlatform : public Platform {
Task* task, ExpectedRuntime expected_runtime) override;
virtual void CallOnForegroundThread(v8::Isolate* isolate,
Task* task) override;
+ virtual void CallDelayedOnForegroundThread(Isolate* isolate, Task* task,
+ double delay_in_seconds) override;
double MonotonicallyIncreasingTime() override;
private:
static const int kMaxThreadPoolSize;
+ Task* PopTaskInMainThreadQueue(v8::Isolate* isolate);
+ Task* PopTaskInMainThreadDelayedQueue(v8::Isolate* isolate);
+
base::Mutex lock_;
bool initialized_;
int thread_pool_size_;
@@ -49,6 +55,12 @@ class DefaultPlatform : public Platform {
TaskQueue queue_;
std::map<v8::Isolate*, std::queue<Task*> > main_thread_queue_;
+ typedef std::pair<double, Task*> DelayedEntry;
+ std::map<v8::Isolate*,
+ std::priority_queue<DelayedEntry, std::vector<DelayedEntry>,
+ std::greater<DelayedEntry> > >
+ main_thread_delayed_queue_;
+
DISALLOW_COPY_AND_ASSIGN(DefaultPlatform);
};