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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/platform/heap/Handle.h ('k') | Source/wtf/wtf.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef WTF_UnretainedPtr_h
6 #define WTF_UnretainedPtr_h
7
8 // UnretainedPtr should be used when a pointer of a GarbageCollected object
9 // is passed to a thread (via postTask) that is not attached to Blink GC.
10 //
11 // postTask(new Task(WTF::bind(&function, UnretainedPtr<GarbageCollectedObject >(this))));
12 //
13 // Without UnretainedPtr specified, the target thread keeps |this| pointer alive
14 // by creating a CrossThreadPersistent handle for the pointer. With
15 // UnretainedPtr specified, the target thread doesn't keep |this| pointer alive.
16 //
17 // If the target thread is not attached to Blink GC, the thread is not allowed
18 // to create a CrossThreadPersistent handle, so you need to specify
19 // UnretainedPtr. In this case, you need to write code so that |this| pointer
20 // is kept alive until the target thread finishes processing the task.
21
22 namespace WTF {
23
24 template<typename T>
25 class UnretainedPtr {
26 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(UnretainedPtr);
27 WTF_DISALLOW_ZERO_ASSIGNMENT(UnretainedPtr);
28 public:
29 UnretainedPtr(std::nullptr_t) : m_ptr(0) { }
30 UnretainedPtr(T* ptr) : m_ptr(ptr) { }
31 operator T*() const { return m_ptr; }
32 template<typename U>
33 operator RawPtr<U>() const { return m_ptr; }
34
35 private:
36 T* m_ptr;
37 };
38
39 } // namespace WTF
40
41 using WTF::UnretainedPtr;
42
43 #endif
OLDNEW
« 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