OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // A "smart" pointer type with reference tracking. Every pointer to a | 5 // A "smart" pointer type with reference tracking. Every pointer to a |
6 // particular object is kept on a circular linked list. When the last pointer | 6 // particular object is kept on a circular linked list. When the last pointer |
7 // to an object is destroyed or reassigned, the object is deleted. | 7 // to an object is destroyed or reassigned, the object is deleted. |
8 // | 8 // |
9 // Used properly, this deletes the object when the last reference goes away. | 9 // Used properly, this deletes the object when the last reference goes away. |
10 // There are several caveats: | 10 // There are several caveats: |
(...skipping 16 matching lines...) Expand all Loading... |
27 // | 27 // |
28 // Thread Safety: | 28 // Thread Safety: |
29 // A linked_ptr is NOT thread safe. Copying a linked_ptr object is | 29 // A linked_ptr is NOT thread safe. Copying a linked_ptr object is |
30 // effectively a read-write operation. | 30 // effectively a read-write operation. |
31 // | 31 // |
32 // Alternative: to linked_ptr is shared_ptr, which | 32 // Alternative: to linked_ptr is shared_ptr, which |
33 // - is also two pointers in size (8 bytes for 32 bit addresses) | 33 // - is also two pointers in size (8 bytes for 32 bit addresses) |
34 // - is thread safe for copying and deletion | 34 // - is thread safe for copying and deletion |
35 // - supports weak_ptrs | 35 // - supports weak_ptrs |
36 | 36 |
37 #ifndef BASE_LINKED_PTR_H_ | 37 #ifndef BASE_MEMORY_LINKED_PTR_H_ |
38 #define BASE_LINKED_PTR_H_ | 38 #define BASE_MEMORY_LINKED_PTR_H_ |
39 #pragma once | 39 #pragma once |
40 | 40 |
41 #include "base/logging.h" // for CHECK macros | 41 #include "base/logging.h" // for CHECK macros |
42 | 42 |
43 // This is used internally by all instances of linked_ptr<>. It needs to be | 43 // This is used internally by all instances of linked_ptr<>. It needs to be |
44 // a non-template class because different types of linked_ptr<> can refer to | 44 // a non-template class because different types of linked_ptr<> can refer to |
45 // the same object (linked_ptr<Superclass>(obj) vs linked_ptr<Subclass>(obj)). | 45 // the same object (linked_ptr<Superclass>(obj) vs linked_ptr<Subclass>(obj)). |
46 // So, it needs to be possible for different types of linked_ptr to participate | 46 // So, it needs to be possible for different types of linked_ptr to participate |
47 // in the same circular linked list, so we need a single class type here. | 47 // in the same circular linked list, so we need a single class type here. |
48 // | 48 // |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 } | 172 } |
173 | 173 |
174 // A function to convert T* into linked_ptr<T> | 174 // A function to convert T* into linked_ptr<T> |
175 // Doing e.g. make_linked_ptr(new FooBarBaz<type>(arg)) is a shorter notation | 175 // Doing e.g. make_linked_ptr(new FooBarBaz<type>(arg)) is a shorter notation |
176 // for linked_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) | 176 // for linked_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) |
177 template <typename T> | 177 template <typename T> |
178 linked_ptr<T> make_linked_ptr(T* ptr) { | 178 linked_ptr<T> make_linked_ptr(T* ptr) { |
179 return linked_ptr<T>(ptr); | 179 return linked_ptr<T>(ptr); |
180 } | 180 } |
181 | 181 |
182 #endif // BASE_LINKED_PTR_H_ | 182 #endif // BASE_MEMORY_LINKED_PTR_H_ |
OLD | NEW |