| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 SkOnce_DEFINED | 8 #ifndef SkOnce_DEFINED |
| 9 #define SkOnce_DEFINED | 9 #define SkOnce_DEFINED |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // SK_DECLARE_STATIC_ONCE(once); | 23 // SK_DECLARE_STATIC_ONCE(once); |
| 24 // SkOnce(&once, register_my_stuff, GetGlobalRegistry()); | 24 // SkOnce(&once, register_my_stuff, GetGlobalRegistry()); |
| 25 // } | 25 // } |
| 26 // | 26 // |
| 27 // No matter how many times you call EnsureRegistered(), register_my_stuff will
be called just once. | 27 // No matter how many times you call EnsureRegistered(), register_my_stuff will
be called just once. |
| 28 // OnceTest.cpp also should serve as a few other simple examples. | 28 // OnceTest.cpp also should serve as a few other simple examples. |
| 29 | 29 |
| 30 #include "SkAtomics.h" | 30 #include "SkAtomics.h" |
| 31 #include "SkSpinlock.h" | 31 #include "SkSpinlock.h" |
| 32 | 32 |
| 33 // This must be used in a global scope, not in fuction scope or as a class membe
r. | 33 // This must be used in a global scope, not in function scope or as a class memb
er. |
| 34 #define SK_DECLARE_STATIC_ONCE(name) namespace {} static SkOnceFlag name | 34 #define SK_DECLARE_STATIC_ONCE(name) namespace {} static SkOnceFlag name |
| 35 | 35 |
| 36 class SkOnceFlag; | 36 class SkOnceFlag; |
| 37 | 37 |
| 38 inline void SkOnce(SkOnceFlag* once, void (*f)()); | 38 inline void SkOnce(SkOnceFlag* once, void (*f)()); |
| 39 | 39 |
| 40 template <typename Arg> | 40 template <typename Arg> |
| 41 inline void SkOnce(SkOnceFlag* once, void (*f)(Arg), Arg arg); | 41 inline void SkOnce(SkOnceFlag* once, void (*f)(Arg), Arg arg); |
| 42 | 42 |
| 43 // If you've already got a lock and a flag to use, this variant lets you avoid a
n extra SkOnceFlag. | 43 // If you've already got a lock and a flag to use, this variant lets you avoid a
n extra SkOnceFlag. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 inline void SkOnce(SkOnceFlag* once, void (*func)()) { | 130 inline void SkOnce(SkOnceFlag* once, void (*func)()) { |
| 131 return SkOnce(once, sk_once_no_arg_adaptor, func); | 131 return SkOnce(once, sk_once_no_arg_adaptor, func); |
| 132 } | 132 } |
| 133 | 133 |
| 134 template <typename Lock> | 134 template <typename Lock> |
| 135 inline void SkOnce(bool* done, Lock* lock, void (*func)()) { | 135 inline void SkOnce(bool* done, Lock* lock, void (*func)()) { |
| 136 return SkOnce(done, lock, sk_once_no_arg_adaptor, func); | 136 return SkOnce(done, lock, sk_once_no_arg_adaptor, func); |
| 137 } | 137 } |
| 138 | 138 |
| 139 #endif // SkOnce_DEFINED | 139 #endif // SkOnce_DEFINED |
| OLD | NEW |