| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkOncePtr_DEFINED | 8 #ifndef SkOncePtr_DEFINED |
| 9 #define SkOncePtr_DEFINED | 9 #define SkOncePtr_DEFINED |
| 10 | 10 |
| 11 #include "SkAtomics.h" | 11 #include "../private/SkAtomics.h" |
| 12 #include "SkUniquePtr.h" | 12 #include "SkUniquePtr.h" |
| 13 | 13 |
| 14 template <typename T> class SkBaseOncePtr; | 14 template <typename T> class SkBaseOncePtr; |
| 15 | 15 |
| 16 // Use this to create a global static pointer that's intialized exactly once whe
n you call get(). | 16 // Use this to create a global static pointer that's intialized exactly once whe
n you call get(). |
| 17 #define SK_DECLARE_STATIC_ONCE_PTR(type, name) namespace {} static SkBaseOncePtr
<type> name; | 17 #define SK_DECLARE_STATIC_ONCE_PTR(type, name) namespace {} static SkBaseOncePtr
<type> name; |
| 18 | 18 |
| 19 // Use this for a local or member pointer that's initialized exactly once when y
ou call get(). | 19 // Use this for a local or member pointer that's initialized exactly once when y
ou call get(). |
| 20 template <typename T, typename Delete = skstd::default_delete<T>> | 20 template <typename T, typename Delete = skstd::default_delete<T>> |
| 21 class SkOncePtr : SkNoncopyable { | 21 class SkOncePtr : SkNoncopyable { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // TODO: If state == 1 spin until it's not? | 97 // TODO: If state == 1 spin until it's not? |
| 98 } | 98 } |
| 99 | 99 |
| 100 // fState == 0 --> we have not created our ptr yet | 100 // fState == 0 --> we have not created our ptr yet |
| 101 // fState == 1 --> someone is in the middle of creating our ptr | 101 // fState == 1 --> someone is in the middle of creating our ptr |
| 102 // else --> (T*)fState is our ptr | 102 // else --> (T*)fState is our ptr |
| 103 mutable uintptr_t fState; | 103 mutable uintptr_t fState; |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 #endif//SkOncePtr_DEFINED | 106 #endif//SkOncePtr_DEFINED |
| OLD | NEW |