OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 MOJO_UTIL_WEAK_PTR_INTERNAL_H_ |
| 6 #define MOJO_UTIL_WEAK_PTR_INTERNAL_H_ |
| 7 |
| 8 #include <assert.h> |
| 9 |
| 10 #include "mojo/edk/util/ref_counted.h" |
| 11 #include "mojo/public/cpp/system/macros.h" |
| 12 |
| 13 namespace mojo { |
| 14 namespace util { |
| 15 namespace internal { |
| 16 |
| 17 // |WeakPtr<T>|s have a reference to a |WeakPtrFlag| to determine whether they |
| 18 // are valid (non-null) or not. We do not store a |T*| in this object since |
| 19 // there may also be |WeakPtr<U>|s to the same object, where |U| is a superclass |
| 20 // of |T|. |
| 21 // |
| 22 // This class in not thread-safe, though references may be released on any |
| 23 // thread (allowing weak pointers to be destroyed/reset/reassigned on any |
| 24 // thread). |
| 25 class WeakPtrFlag : public RefCountedThreadSafe<WeakPtrFlag> { |
| 26 public: |
| 27 WeakPtrFlag(); |
| 28 ~WeakPtrFlag(); |
| 29 |
| 30 bool is_valid() const { return is_valid_; } |
| 31 |
| 32 void Invalidate(); |
| 33 |
| 34 private: |
| 35 bool is_valid_; |
| 36 |
| 37 MOJO_DISALLOW_COPY_AND_ASSIGN(WeakPtrFlag); |
| 38 }; |
| 39 |
| 40 } // namespace internal |
| 41 } // namespace util |
| 42 } // namespace mojo |
| 43 |
| 44 #endif // MOJO_UTIL_WEAK_PTR_INTERNAL_H_ |
OLD | NEW |