| 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 10 matching lines...) Expand all  Loading... | 
| 21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 
| 22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 
| 23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 
| 24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
| 25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
| 26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
| 27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
| 28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
| 29  */ | 29  */ | 
| 30 | 30 | 
| 31 #ifndef MessageLoopInterruptor_h | 31 #ifndef WTF_Ptr_h | 
| 32 #define MessageLoopInterruptor_h | 32 #define WTF_Ptr_h | 
| 33 | 33 | 
| 34 #include "heap/ThreadState.h" | 34 // Ptr is a simple wrapper for a raw pointer that provides the | 
| 35 #include "public/platform/WebThread.h" | 35 // interface (get, clear) of other pointer types such as RefPtr, | 
|  | 36 // Persistent and Member. This is used for the Blink garbage | 
|  | 37 // collection work in order to be able to write shared code that will | 
|  | 38 // use reference counting or garbage collection based on a | 
|  | 39 // compile-time flag. | 
| 36 | 40 | 
| 37 namespace WebCore { | 41 namespace WTF { | 
| 38 | 42 | 
| 39 class MessageLoopInterruptor : public ThreadState::Interruptor { | 43 template<typename T> | 
|  | 44 class Ptr { | 
| 40 public: | 45 public: | 
| 41     explicit MessageLoopInterruptor(blink::WebThread* thread) : m_thread(thread)
     { } | 46     Ptr(T* ptr) : m_ptr(ptr) { } | 
|  | 47     Ptr(std::nullptr_t) : m_ptr(0) { } | 
| 42 | 48 | 
| 43     virtual void requestInterrupt() OVERRIDE | 49     template<typename U> | 
|  | 50     Ptr(const Ptr<U>& other) | 
|  | 51         : m_ptr(other.get()) | 
| 44     { | 52     { | 
| 45         // GCTask has an empty run() method. Its only purpose is to guarantee |  | 
| 46         // that MessageLoop will have a task to process which will result |  | 
| 47         // in PendingGCRunner::didProcessTask being executed. |  | 
| 48         m_thread->postTask(new GCTask); |  | 
| 49     } | 53     } | 
| 50 | 54 | 
| 51     virtual void clearInterrupt() OVERRIDE { } | 55     T* get() const { return m_ptr; } | 
|  | 56     void clear() { m_ptr = 0; } | 
|  | 57 | 
|  | 58     Ptr& operator=(T* ptr) | 
|  | 59     { | 
|  | 60         m_ptr = ptr; | 
|  | 61         return *this; | 
|  | 62     } | 
|  | 63 | 
|  | 64     Ptr& operator=(std::nullptr_t) | 
|  | 65     { | 
|  | 66         m_ptr = 0; | 
|  | 67         return *this; | 
|  | 68     } | 
|  | 69 | 
|  | 70     operator T*() const { return m_ptr; } | 
|  | 71     T& operator*() const { return *m_ptr; } | 
|  | 72     T* operator->() const { return m_ptr; } | 
|  | 73     bool operator!() const { return !m_ptr; } | 
|  | 74 | 
|  | 75     // This conversion operator allows implicit conversion to bool but | 
|  | 76     // not to other integer types. | 
|  | 77     typedef T* Ptr::*UnspecifiedBoolType; | 
|  | 78     operator UnspecifiedBoolType() const { return m_ptr ? &m_ptr : 0; } | 
| 52 | 79 | 
| 53 private: | 80 private: | 
| 54     class GCTask : public blink::WebThread::Task { | 81     T* m_ptr; | 
| 55     public: |  | 
| 56         virtual ~GCTask() { } |  | 
| 57 |  | 
| 58         virtual void run() OVERRIDE |  | 
| 59         { |  | 
| 60             // Don't do anything here because we don't know if this is |  | 
| 61             // a nested event loop or not. PendingGCRunner::didProcessTask |  | 
| 62             // will enter correct safepoint for us. |  | 
| 63             // We are not calling onInterrupted() because that always |  | 
| 64             // conservatively enters safepoint with pointers on stack. |  | 
| 65         } |  | 
| 66     }; |  | 
| 67 |  | 
| 68     blink::WebThread* m_thread; |  | 
| 69 }; | 82 }; | 
| 70 | 83 | 
| 71 } | 84 } // namespace WTF | 
|  | 85 | 
|  | 86 using WTF::Ptr; | 
| 72 | 87 | 
| 73 #endif | 88 #endif | 
| OLD | NEW | 
|---|