| Index: Source/wtf/Ptr.h
|
| diff --git a/Source/heap/glue/MessageLoopInterruptor.h b/Source/wtf/Ptr.h
|
| similarity index 57%
|
| copy from Source/heap/glue/MessageLoopInterruptor.h
|
| copy to Source/wtf/Ptr.h
|
| index 82d36aa04253999faabc1807605bbd366114d1ba..7608e83813ba3ec1c46df00e3e21e3241abce13c 100644
|
| --- a/Source/heap/glue/MessageLoopInterruptor.h
|
| +++ b/Source/wtf/Ptr.h
|
| @@ -28,46 +28,61 @@
|
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| */
|
|
|
| -#ifndef MessageLoopInterruptor_h
|
| -#define MessageLoopInterruptor_h
|
| +#ifndef WTF_Ptr_h
|
| +#define WTF_Ptr_h
|
|
|
| -#include "heap/ThreadState.h"
|
| -#include "public/platform/WebThread.h"
|
| +// Ptr is a simple wrapper for a raw pointer that provides the
|
| +// interface (get, clear) of other pointer types such as RefPtr,
|
| +// Persistent and Member. This is used for the Blink garbage
|
| +// collection work in order to be able to write shared code that will
|
| +// use reference counting or garbage collection based on a
|
| +// compile-time flag.
|
|
|
| -namespace WebCore {
|
| +namespace WTF {
|
|
|
| -class MessageLoopInterruptor : public ThreadState::Interruptor {
|
| +template<typename T>
|
| +class Ptr {
|
| public:
|
| - explicit MessageLoopInterruptor(blink::WebThread* thread) : m_thread(thread) { }
|
| + Ptr(T* ptr) : m_ptr(ptr) { }
|
| + Ptr(std::nullptr_t) : m_ptr(0) { }
|
|
|
| - virtual void requestInterrupt() OVERRIDE
|
| + template<typename U>
|
| + Ptr(const Ptr<U>& other)
|
| + : m_ptr(other.get())
|
| {
|
| - // GCTask has an empty run() method. Its only purpose is to guarantee
|
| - // that MessageLoop will have a task to process which will result
|
| - // in PendingGCRunner::didProcessTask being executed.
|
| - m_thread->postTask(new GCTask);
|
| }
|
|
|
| - virtual void clearInterrupt() OVERRIDE { }
|
| + T* get() const { return m_ptr; }
|
| + void clear() { m_ptr = 0; }
|
|
|
| -private:
|
| - class GCTask : public blink::WebThread::Task {
|
| - public:
|
| - virtual ~GCTask() { }
|
| + Ptr& operator=(T* ptr)
|
| + {
|
| + m_ptr = ptr;
|
| + return *this;
|
| + }
|
|
|
| - virtual void run() OVERRIDE
|
| - {
|
| - // Don't do anything here because we don't know if this is
|
| - // a nested event loop or not. PendingGCRunner::didProcessTask
|
| - // will enter correct safepoint for us.
|
| - // We are not calling onInterrupted() because that always
|
| - // conservatively enters safepoint with pointers on stack.
|
| - }
|
| - };
|
| + Ptr& operator=(std::nullptr_t)
|
| + {
|
| + m_ptr = 0;
|
| + return *this;
|
| + }
|
|
|
| - blink::WebThread* m_thread;
|
| + operator T*() const { return m_ptr; }
|
| + T& operator*() const { return *m_ptr; }
|
| + T* operator->() const { return m_ptr; }
|
| + bool operator!() const { return !m_ptr; }
|
| +
|
| + // This conversion operator allows implicit conversion to bool but
|
| + // not to other integer types.
|
| + typedef T* Ptr::*UnspecifiedBoolType;
|
| + operator UnspecifiedBoolType() const { return m_ptr ? &m_ptr : 0; }
|
| +
|
| +private:
|
| + T* m_ptr;
|
| };
|
|
|
| -}
|
| +} // namespace WTF
|
| +
|
| +using WTF::Ptr;
|
|
|
| #endif
|
|
|