| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "core/inspector/InspectorTaskRunner.h" |
| 7 |
| 8 #include "wtf/Deque.h" |
| 9 #include "wtf/ThreadingPrimitives.h" |
| 10 #include <v8.h> |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 class InspectorTaskRunner::ThreadSafeTaskQueue { |
| 15 WTF_MAKE_NONCOPYABLE(ThreadSafeTaskQueue); |
| 16 public: |
| 17 ThreadSafeTaskQueue() { } |
| 18 PassOwnPtr<Task> tryTake() |
| 19 { |
| 20 MutexLocker lock(m_mutex); |
| 21 if (m_queue.isEmpty()) |
| 22 return nullptr; |
| 23 return m_queue.takeFirst(); |
| 24 } |
| 25 void append(PassOwnPtr<Task> task) |
| 26 { |
| 27 MutexLocker lock(m_mutex); |
| 28 m_queue.append(task); |
| 29 } |
| 30 private: |
| 31 Mutex m_mutex; |
| 32 Deque<OwnPtr<Task>> m_queue; |
| 33 }; |
| 34 |
| 35 |
| 36 InspectorTaskRunner::InspectorTaskRunner(v8::Isolate* isolate) |
| 37 : m_isolate(isolate) |
| 38 , m_taskQueue(adoptPtr(new ThreadSafeTaskQueue)) |
| 39 , m_ignoreInterrupts(false) |
| 40 { |
| 41 } |
| 42 |
| 43 InspectorTaskRunner::~InspectorTaskRunner() |
| 44 { |
| 45 } |
| 46 |
| 47 void InspectorTaskRunner::interruptAndRun(PassOwnPtr<Task> task) |
| 48 { |
| 49 m_taskQueue->append(task); |
| 50 m_isolate->RequestInterrupt(&v8InterruptCallback, this); |
| 51 } |
| 52 |
| 53 void InspectorTaskRunner::runPendingTasks() |
| 54 { |
| 55 while (true) { |
| 56 OwnPtr<Task> task = m_taskQueue->tryTake(); |
| 57 if (!task) |
| 58 return; |
| 59 task->run(); |
| 60 } |
| 61 } |
| 62 |
| 63 void InspectorTaskRunner::v8InterruptCallback(v8::Isolate*, void* data) |
| 64 { |
| 65 InspectorTaskRunner* runner = static_cast<InspectorTaskRunner*>(data); |
| 66 if (runner->m_ignoreInterrupts) |
| 67 return; |
| 68 runner->runPendingTasks(); |
| 69 } |
| 70 |
| 71 } |
| OLD | NEW |