| 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 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 } | 33 } |
| 34 | 34 |
| 35 operator T*() const { | 35 operator T*() const { |
| 36 return (T*)fOnce; | 36 return (T*)fOnce; |
| 37 } | 37 } |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 SkBaseOncePtr<T> fOnce; | 40 SkBaseOncePtr<T> fOnce; |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 // If you ask for SkOncePtr<T[]>, we'll clean up with delete[] by default. |
| 44 template <typename T> |
| 45 class SkOncePtr<T[]> : public SkOncePtr<T, skstd::default_delete<T[]>> {}; |
| 46 |
| 43 /* TODO(mtklein): in next CL | 47 /* TODO(mtklein): in next CL |
| 44 typedef SkBaseOncePtr<void> SkOnceFlag; | 48 typedef SkBaseOncePtr<void> SkOnceFlag; |
| 45 #define SK_DECLARE_STATIC_ONCE(name) namespace {} static SkOnceFlag name | 49 #define SK_DECLARE_STATIC_ONCE(name) namespace {} static SkOnceFlag name |
| 46 | 50 |
| 47 template <typename F> | 51 template <typename F> |
| 48 inline void SkOnce(SkOnceFlag* once, const F& f) { | 52 inline void SkOnce(SkOnceFlag* once, const F& f) { |
| 49 once->get([&]{ f(); return (void*)2; }); | 53 once->get([&]{ f(); return (void*)2; }); |
| 50 } | 54 } |
| 51 */ | 55 */ |
| 52 | 56 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 } | 98 } |
| 95 | 99 |
| 96 private: | 100 private: |
| 97 // fState == 0 --> we have not created our ptr yet | 101 // fState == 0 --> we have not created our ptr yet |
| 98 // fState == 1 --> someone is in the middle of creating our ptr | 102 // fState == 1 --> someone is in the middle of creating our ptr |
| 99 // else --> (T*)fState is our ptr | 103 // else --> (T*)fState is our ptr |
| 100 mutable SkAtomic<uintptr_t> fState; | 104 mutable SkAtomic<uintptr_t> fState; |
| 101 }; | 105 }; |
| 102 | 106 |
| 103 #endif//SkOncePtr_DEFINED | 107 #endif//SkOncePtr_DEFINED |
| OLD | NEW |