OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // Weak pointers help in cases where you have many objects referring back to a | 5 // Weak pointers help in cases where you have many objects referring back to a |
6 // shared object and you wish for the lifetime of the shared object to not be | 6 // shared object and you wish for the lifetime of the shared object to not be |
7 // bound to the lifetime of the referrers. In other words, this is useful when | 7 // bound to the lifetime of the referrers. In other words, this is useful when |
8 // reference counting is not a good fit. | 8 // reference counting is not a good fit. |
9 // | 9 // |
10 // A common alternative to weak pointers is to have the shared object hold a | 10 // A common alternative to weak pointers is to have the shared object hold a |
(...skipping 30 matching lines...) Expand all Loading... |
41 // Given the above classes, a consumer may allocate a Controller object, call | 41 // Given the above classes, a consumer may allocate a Controller object, call |
42 // SpawnWorker several times, and then destroy the Controller object before all | 42 // SpawnWorker several times, and then destroy the Controller object before all |
43 // of the workers have completed. Because the Worker class only holds a weak | 43 // of the workers have completed. Because the Worker class only holds a weak |
44 // pointer to the Controller, we don't have to worry about the Worker | 44 // pointer to the Controller, we don't have to worry about the Worker |
45 // dereferencing the Controller back pointer after the Controller has been | 45 // dereferencing the Controller back pointer after the Controller has been |
46 // destroyed. | 46 // destroyed. |
47 // | 47 // |
48 // WARNING: weak pointers are not threadsafe!!! You must only use a WeakPtr | 48 // WARNING: weak pointers are not threadsafe!!! You must only use a WeakPtr |
49 // instance on thread where it was created. | 49 // instance on thread where it was created. |
50 | 50 |
51 #ifndef BASE_WEAK_PTR_H_ | 51 #ifndef BASE_MEMORY_WEAK_PTR_H_ |
52 #define BASE_WEAK_PTR_H_ | 52 #define BASE_MEMORY_WEAK_PTR_H_ |
53 #pragma once | 53 #pragma once |
54 | 54 |
55 #include "base/logging.h" | 55 #include "base/logging.h" |
56 #include "base/ref_counted.h" | 56 #include "base/memory/ref_counted.h" |
57 #include "base/threading/non_thread_safe.h" | 57 #include "base/threading/non_thread_safe.h" |
58 | 58 |
59 namespace base { | 59 namespace base { |
60 | 60 |
61 namespace internal { | 61 namespace internal { |
62 // These classes are part of the WeakPtr implementation. | 62 // These classes are part of the WeakPtr implementation. |
63 // DO NOT USE THESE CLASSES DIRECTLY YOURSELF. | 63 // DO NOT USE THESE CLASSES DIRECTLY YOURSELF. |
64 | 64 |
65 class WeakReference { | 65 class WeakReference { |
66 public: | 66 public: |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 } | 235 } |
236 | 236 |
237 private: | 237 private: |
238 internal::WeakReferenceOwner weak_reference_owner_; | 238 internal::WeakReferenceOwner weak_reference_owner_; |
239 T* ptr_; | 239 T* ptr_; |
240 DISALLOW_IMPLICIT_CONSTRUCTORS(WeakPtrFactory); | 240 DISALLOW_IMPLICIT_CONSTRUCTORS(WeakPtrFactory); |
241 }; | 241 }; |
242 | 242 |
243 } // namespace base | 243 } // namespace base |
244 | 244 |
245 #endif // BASE_WEAK_PTR_H_ | 245 #endif // BASE_MEMORY_WEAK_PTR_H_ |
OLD | NEW |