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

Unified Diff: Source/wtf/UnretainedPtr.h

Issue 670113002: Oilpan: A thread that is not attached to Oilpan shouldn't create a CrossThreadPersistent Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 2 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/platform/heap/Handle.h ('k') | Source/wtf/wtf.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/UnretainedPtr.h
diff --git a/Source/wtf/UnretainedPtr.h b/Source/wtf/UnretainedPtr.h
new file mode 100644
index 0000000000000000000000000000000000000000..4e8c7410fa70da8fbda563a787a8ebe8a219c5d7
--- /dev/null
+++ b/Source/wtf/UnretainedPtr.h
@@ -0,0 +1,43 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WTF_UnretainedPtr_h
+#define WTF_UnretainedPtr_h
+
+// UnretainedPtr should be used when a pointer of a GarbageCollected object
+// is passed to a thread (via postTask) that is not attached to Blink GC.
+//
+// postTask(new Task(WTF::bind(&function, UnretainedPtr<GarbageCollectedObject>(this))));
+//
+// Without UnretainedPtr specified, the target thread keeps |this| pointer alive
+// by creating a CrossThreadPersistent handle for the pointer. With
+// UnretainedPtr specified, the target thread doesn't keep |this| pointer alive.
+//
+// If the target thread is not attached to Blink GC, the thread is not allowed
+// to create a CrossThreadPersistent handle, so you need to specify
+// UnretainedPtr. In this case, you need to write code so that |this| pointer
+// is kept alive until the target thread finishes processing the task.
+
+namespace WTF {
+
+template<typename T>
+class UnretainedPtr {
+ WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(UnretainedPtr);
+ WTF_DISALLOW_ZERO_ASSIGNMENT(UnretainedPtr);
+public:
+ UnretainedPtr(std::nullptr_t) : m_ptr(0) { }
+ UnretainedPtr(T* ptr) : m_ptr(ptr) { }
+ operator T*() const { return m_ptr; }
+ template<typename U>
+ operator RawPtr<U>() const { return m_ptr; }
+
+private:
+ T* m_ptr;
+};
+
+} // namespace WTF
+
+using WTF::UnretainedPtr;
+
+#endif
« no previous file with comments | « Source/platform/heap/Handle.h ('k') | Source/wtf/wtf.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698