| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 // This class has no constructor and must be zero-initialized (the macro above d
oes this). | 52 // This class has no constructor and must be zero-initialized (the macro above d
oes this). |
| 53 class SkOnceFlag { | 53 class SkOnceFlag { |
| 54 public: | 54 public: |
| 55 bool* mutableDone() { return &fDone; } | 55 bool* mutableDone() { return &fDone; } |
| 56 | 56 |
| 57 void acquire() { fSpinlock.acquire(); } | 57 void acquire() { fSpinlock.acquire(); } |
| 58 void release() { fSpinlock.release(); } | 58 void release() { fSpinlock.release(); } |
| 59 | 59 |
| 60 private: | 60 private: |
| 61 bool fDone; | 61 bool fDone; |
| 62 SkPODSpinlock fSpinlock; | 62 SkSpinlock fSpinlock; |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 // We've pulled a pretty standard double-checked locking implementation apart | 65 // We've pulled a pretty standard double-checked locking implementation apart |
| 66 // into its main fast path and a slow path that's called when we suspect the | 66 // into its main fast path and a slow path that's called when we suspect the |
| 67 // one-time code hasn't run yet. | 67 // one-time code hasn't run yet. |
| 68 | 68 |
| 69 // This is the guts of the code, called when we suspect the one-time code hasn't
been run yet. | 69 // This is the guts of the code, called when we suspect the one-time code hasn't
been run yet. |
| 70 // This should be rarely called, so we separate it from SkOnce and don't mark it
as inline. | 70 // This should be rarely called, so we separate it from SkOnce and don't mark it
as inline. |
| 71 // (We don't mind if this is an actual function call, but odds are it'll be inli
ned anyway.) | 71 // (We don't mind if this is an actual function call, but odds are it'll be inli
ned anyway.) |
| 72 template <typename Lock, typename Arg> | 72 template <typename Lock, typename Arg> |
| (...skipping 57 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 |