| 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();
|
| +}
|
| +
|
| +}
|
|
|