Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1311)

Unified Diff: src/libplatform/default-platform.cc

Issue 1179153002: Add V8 platform API to call delayed task. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Provide empty body to enable roll in Chromium. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/libplatform/default-platform.h ('k') | test/unittests/libplatform/default-platform-unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/libplatform/default-platform.cc
diff --git a/src/libplatform/default-platform.cc b/src/libplatform/default-platform.cc
index 1ac52f919f3f4889037512e332a5b07fba25146c..2885d55de7066c19546cee6a82587ffa3b050ad9 100644
--- a/src/libplatform/default-platform.cc
+++ b/src/libplatform/default-platform.cc
@@ -78,23 +78,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 +141,14 @@ void DefaultPlatform::CallOnForegroundThread(v8::Isolate* isolate, Task* task) {
}
+void DefaultPlatform::CallDelayedOnForegroundThread(Isolate* isolate,
+ Task* task,
+ double delay_in_seconds) {
+ 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);
« no previous file with comments | « src/libplatform/default-platform.h ('k') | test/unittests/libplatform/default-platform-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698