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

Unified Diff: src/global-handles.cc

Issue 1209403005: Let the second pass phantom callbacks run in a separate task on the foreground thread. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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/global-handles.h ('k') | src/list.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/global-handles.cc
diff --git a/src/global-handles.cc b/src/global-handles.cc
index aa6542baee922f8f4e517cd6764f8b8ed71290ee..004e55b5bfcd8162fa4bb44d18d8111b35daa13a 100644
--- a/src/global-handles.cc
+++ b/src/global-handles.cc
@@ -495,6 +495,35 @@ class GlobalHandles::NodeIterator {
DISALLOW_COPY_AND_ASSIGN(NodeIterator);
};
+class GlobalHandles::PendingPhantomCallbacksSecondPassTask : public v8::Task {
+ public:
+ // Takes ownership of the contents of pending_phantom_callbacks, leaving it in
+ // the same state it would be after a call to Clear().
+ PendingPhantomCallbacksSecondPassTask(
+ List<PendingPhantomCallback>* pending_phantom_callbacks, Isolate* isolate)
+ : isolate_(isolate) {
+ pending_phantom_callbacks_.Swap(pending_phantom_callbacks);
+ }
+
+ ~PendingPhantomCallbacksSecondPassTask() override {}
+
+ void Run() override {
+ while (pending_phantom_callbacks_.length() != 0) {
+ auto callback = pending_phantom_callbacks_.RemoveLast();
+ DCHECK(callback.node() == nullptr);
+ // No second pass callback required.
+ if (callback.callback() == nullptr) continue;
+ // Fire second pass callback
+ callback.Invoke(isolate_);
+ }
+ pending_phantom_callbacks_.Clear();
+ }
+
+ private:
+ List<PendingPhantomCallback> pending_phantom_callbacks_;
+ Isolate* isolate_;
+};
jochen (gone - plz use gerrit) 2015/07/03 12:42:27 nit. DISALLOW_COPY_AND_ASSIGN(PendingPhantomCallba
epertoso 2015/07/03 14:38:00 Done.
+
GlobalHandles::GlobalHandles(Isolate* isolate)
: isolate_(isolate),
@@ -804,14 +833,11 @@ int GlobalHandles::DispatchPendingPhantomCallbacks() {
freed_nodes++;
}
}
- // The second pass empties the list.
- while (pending_phantom_callbacks_.length() != 0) {
- auto callback = pending_phantom_callbacks_.RemoveLast();
- DCHECK(callback.node() == nullptr);
- // No second pass callback required.
- if (callback.callback() == nullptr) continue;
- // Fire second pass callback.
- callback.Invoke(isolate());
+ if (pending_phantom_callbacks_.length() > 0) {
+ auto* task = new PendingPhantomCallbacksSecondPassTask(
+ &pending_phantom_callbacks_, isolate());
+ V8::GetCurrentPlatform()->CallOnForegroundThread(
+ reinterpret_cast<v8::Isolate*>(isolate()), task);
}
pending_phantom_callbacks_.Clear();
return freed_nodes;
« no previous file with comments | « src/global-handles.h ('k') | src/list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698