| 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 11 matching lines...) Expand all Loading... |
| 22 // SkOnce(&once, set_up_my_singleton, &singleton); | 22 // SkOnce(&once, set_up_my_singleton, &singleton); |
| 23 // SkASSERT(NULL != singleton); | 23 // SkASSERT(NULL != singleton); |
| 24 // return *singleton; | 24 // return *singleton; |
| 25 // } | 25 // } |
| 26 // | 26 // |
| 27 // OnceTest.cpp also should serve as a few other simple examples. | 27 // OnceTest.cpp also should serve as a few other simple examples. |
| 28 // | 28 // |
| 29 // You may optionally pass SkOnce a second function to be called at exit for cle
anup. | 29 // You may optionally pass SkOnce a second function to be called at exit for cle
anup. |
| 30 | 30 |
| 31 #include "SkDynamicAnnotations.h" | 31 #include "SkDynamicAnnotations.h" |
| 32 #include "SkThread.h" |
| 32 #include "SkTypes.h" | 33 #include "SkTypes.h" |
| 33 | 34 |
| 34 #include "../../src/core/SkThread.h" | |
| 35 | |
| 36 #define SK_ONCE_INIT { false, { 0, SkDEBUGCODE(0) } } | 35 #define SK_ONCE_INIT { false, { 0, SkDEBUGCODE(0) } } |
| 37 #define SK_DECLARE_STATIC_ONCE(name) static SkOnceFlag name = SK_ONCE_INIT | 36 #define SK_DECLARE_STATIC_ONCE(name) static SkOnceFlag name = SK_ONCE_INIT |
| 38 | 37 |
| 39 struct SkOnceFlag; // If manually created, initialize with SkOnceFlag once = SK
_ONCE_INIT | 38 struct SkOnceFlag; // If manually created, initialize with SkOnceFlag once = SK
_ONCE_INIT |
| 40 | 39 |
| 41 template <typename Func, typename Arg> | 40 template <typename Func, typename Arg> |
| 42 inline void SkOnce(SkOnceFlag* once, Func f, Arg arg, void(*atExit)() = NULL); | 41 inline void SkOnce(SkOnceFlag* once, Func f, Arg arg, void(*atExit)() = NULL); |
| 43 | 42 |
| 44 // 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. |
| 45 template <typename Lock, typename Func, typename Arg> | 44 template <typename Lock, typename Func, typename Arg> |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 } | 168 } |
| 170 | 169 |
| 171 template <typename Func, typename Arg> | 170 template <typename Func, typename Arg> |
| 172 inline void SkOnce(SkOnceFlag* once, Func f, Arg arg, void(*atExit)()) { | 171 inline void SkOnce(SkOnceFlag* once, Func f, Arg arg, void(*atExit)()) { |
| 173 return SkOnce(&once->done, &once->lock, f, arg, atExit); | 172 return SkOnce(&once->done, &once->lock, f, arg, atExit); |
| 174 } | 173 } |
| 175 | 174 |
| 176 #undef SK_ANNOTATE_BENIGN_RACE | 175 #undef SK_ANNOTATE_BENIGN_RACE |
| 177 | 176 |
| 178 #endif // SkOnce_DEFINED | 177 #endif // SkOnce_DEFINED |
| OLD | NEW |