| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "platform/CrossThreadFunctional.h" | 34 #include "platform/CrossThreadFunctional.h" |
| 35 #include "platform/WebTaskRunner.h" | 35 #include "platform/WebTaskRunner.h" |
| 36 #include "platform/heap/ThreadState.h" | 36 #include "platform/heap/ThreadState.h" |
| 37 #include "public/platform/WebThread.h" | 37 #include "public/platform/WebThread.h" |
| 38 #include "public/platform/WebTraceLocation.h" | 38 #include "public/platform/WebTraceLocation.h" |
| 39 #include "wtf/PtrUtil.h" | 39 #include "wtf/PtrUtil.h" |
| 40 #include <memory> | 40 #include <memory> |
| 41 | 41 |
| 42 namespace blink { | 42 namespace blink { |
| 43 | 43 |
| 44 class MessageLoopInterruptor final : public BlinkGCInterruptor { | |
| 45 public: | |
| 46 explicit MessageLoopInterruptor(RefPtr<WebTaskRunner> taskRunner) | |
| 47 : m_taskRunner(std::move(taskRunner)) {} | |
| 48 | |
| 49 void requestInterrupt() override { | |
| 50 // GCTask has an empty run() method. Its only purpose is to guarantee | |
| 51 // that MessageLoop will have a task to process which will result | |
| 52 // in GCTaskRunner::didProcessTask being executed. | |
| 53 m_taskRunner->postTask(BLINK_FROM_HERE, crossThreadBind(&runGCTask)); | |
| 54 } | |
| 55 | |
| 56 private: | |
| 57 static void runGCTask() { | |
| 58 // Don't do anything here because we don't know if this is | |
| 59 // a nested event loop or not. GCTaskRunner::didProcessTask | |
| 60 // will enter correct safepoint for us. | |
| 61 // We are not calling onInterrupted() because that always | |
| 62 // conservatively enters safepoint with pointers on stack. | |
| 63 } | |
| 64 | |
| 65 RefPtr<WebTaskRunner> m_taskRunner; | |
| 66 }; | |
| 67 | |
| 68 class GCTaskObserver final : public WebThread::TaskObserver { | 44 class GCTaskObserver final : public WebThread::TaskObserver { |
| 69 USING_FAST_MALLOC(GCTaskObserver); | 45 USING_FAST_MALLOC(GCTaskObserver); |
| 70 | 46 |
| 71 public: | 47 public: |
| 72 GCTaskObserver() : m_nesting(0) {} | 48 GCTaskObserver() : m_nesting(0) {} |
| 73 | 49 |
| 74 ~GCTaskObserver() { | 50 ~GCTaskObserver() { |
| 75 // m_nesting can be 1 if this was unregistered in a task and | 51 // m_nesting can be 1 if this was unregistered in a task and |
| 76 // didProcessTask was not called. | 52 // didProcessTask was not called. |
| 77 ASSERT(!m_nesting || m_nesting == 1); | 53 ASSERT(!m_nesting || m_nesting == 1); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 96 }; | 72 }; |
| 97 | 73 |
| 98 class GCTaskRunner final { | 74 class GCTaskRunner final { |
| 99 USING_FAST_MALLOC(GCTaskRunner); | 75 USING_FAST_MALLOC(GCTaskRunner); |
| 100 | 76 |
| 101 public: | 77 public: |
| 102 explicit GCTaskRunner(WebThread* thread) | 78 explicit GCTaskRunner(WebThread* thread) |
| 103 : m_gcTaskObserver(WTF::wrapUnique(new GCTaskObserver)), | 79 : m_gcTaskObserver(WTF::wrapUnique(new GCTaskObserver)), |
| 104 m_thread(thread) { | 80 m_thread(thread) { |
| 105 m_thread->addTaskObserver(m_gcTaskObserver.get()); | 81 m_thread->addTaskObserver(m_gcTaskObserver.get()); |
| 106 ThreadState::current()->addInterruptor(WTF::wrapUnique( | |
| 107 new MessageLoopInterruptor(thread->getWebTaskRunner()))); | |
| 108 } | 82 } |
| 109 | 83 |
| 110 ~GCTaskRunner() { m_thread->removeTaskObserver(m_gcTaskObserver.get()); } | 84 ~GCTaskRunner() { m_thread->removeTaskObserver(m_gcTaskObserver.get()); } |
| 111 | 85 |
| 112 private: | 86 private: |
| 113 std::unique_ptr<GCTaskObserver> m_gcTaskObserver; | 87 std::unique_ptr<GCTaskObserver> m_gcTaskObserver; |
| 114 WebThread* m_thread; | 88 WebThread* m_thread; |
| 115 }; | 89 }; |
| 116 | 90 |
| 117 } // namespace blink | 91 } // namespace blink |
| 118 | 92 |
| 119 #endif | 93 #endif |
| OLD | NEW |