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

Unified Diff: Source/core/inspector/InspectorTaskRunner.cpp

Issue 1163923005: Fix crash in inspector-protocol/debugger/debugger-pause-dedicated-worker.html (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Removed printf Created 5 years, 7 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 | « Source/core/inspector/InspectorTaskRunner.h ('k') | Source/core/inspector/WorkerDebuggerAgent.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/inspector/InspectorTaskRunner.cpp
diff --git a/Source/core/inspector/InspectorTaskRunner.cpp b/Source/core/inspector/InspectorTaskRunner.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..34143455da079aeecbbfb4be613404702f6a4d4b
--- /dev/null
+++ b/Source/core/inspector/InspectorTaskRunner.cpp
@@ -0,0 +1,71 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "core/inspector/InspectorTaskRunner.h"
+
+#include "wtf/Deque.h"
+#include "wtf/ThreadingPrimitives.h"
+#include <v8.h>
+
+namespace blink {
+
+class InspectorTaskRunner::ThreadSafeTaskQueue {
+ WTF_MAKE_NONCOPYABLE(ThreadSafeTaskQueue);
+public:
+ ThreadSafeTaskQueue() { }
+ PassOwnPtr<Task> tryTake()
+ {
+ MutexLocker lock(m_mutex);
+ if (m_queue.isEmpty())
+ return nullptr;
+ return m_queue.takeFirst();
+ }
+ void append(PassOwnPtr<Task> task)
+ {
+ MutexLocker lock(m_mutex);
+ m_queue.append(task);
+ }
+private:
+ Mutex m_mutex;
+ Deque<OwnPtr<Task>> m_queue;
+};
+
+
+InspectorTaskRunner::InspectorTaskRunner(v8::Isolate* isolate)
+ : m_isolate(isolate)
+ , m_taskQueue(adoptPtr(new ThreadSafeTaskQueue))
+ , m_ignoreInterrupts(false)
+{
+}
+
+InspectorTaskRunner::~InspectorTaskRunner()
+{
+}
+
+void InspectorTaskRunner::interruptAndRun(PassOwnPtr<Task> task)
+{
+ m_taskQueue->append(task);
+ m_isolate->RequestInterrupt(&v8InterruptCallback, this);
+}
+
+void InspectorTaskRunner::runPendingTasks()
+{
+ while (true) {
+ OwnPtr<Task> task = m_taskQueue->tryTake();
+ if (!task)
+ return;
+ task->run();
+ }
+}
+
+void InspectorTaskRunner::v8InterruptCallback(v8::Isolate*, void* data)
+{
+ InspectorTaskRunner* runner = static_cast<InspectorTaskRunner*>(data);
+ if (runner->m_ignoreInterrupts)
+ return;
+ runner->runPendingTasks();
+}
+
+}
« no previous file with comments | « Source/core/inspector/InspectorTaskRunner.h ('k') | Source/core/inspector/WorkerDebuggerAgent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698