Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1514)

Unified Diff: Source/wtf/Ptr.h

Issue 137483003: Add template aliases to support both reference counting and garbage collection for a transition per… (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address comment. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/heap/HeapTest.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « Source/heap/HeapTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698