| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 f(arg); | 76 f(arg); |
| 77 // Also known as a store-store/load-store barrier, this makes sure that
the writes | 77 // Also known as a store-store/load-store barrier, this makes sure that
the writes |
| 78 // done before here---in particular, those done by calling f(arg)---are
observable | 78 // done before here---in particular, those done by calling f(arg)---are
observable |
| 79 // before the writes after the line, *done = true. | 79 // before the writes after the line, *done = true. |
| 80 // | 80 // |
| 81 // In version control terms this is like saying, "check in the work up | 81 // In version control terms this is like saying, "check in the work up |
| 82 // to and including f(arg), then check in *done=true as a subsequent cha
nge". | 82 // to and including f(arg), then check in *done=true as a subsequent cha
nge". |
| 83 // | 83 // |
| 84 // We'll use this in the fast path to make sure f(arg)'s effects are | 84 // We'll use this in the fast path to make sure f(arg)'s effects are |
| 85 // observable whenever we observe *done == true. | 85 // observable whenever we observe *done == true. |
| 86 sk_release_store(done, true); | 86 sk_atomic_store(done, true, sk_memory_order_release); |
| 87 } | 87 } |
| 88 lock->release(); | 88 lock->release(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 // This is our fast path, called all the time. We do really want it to be inlin
ed. | 91 // This is our fast path, called all the time. We do really want it to be inlin
ed. |
| 92 template <typename Lock, typename Arg> | 92 template <typename Lock, typename Arg> |
| 93 inline void SkOnce(bool* done, Lock* lock, void (*f)(Arg), Arg arg) { | 93 inline void SkOnce(bool* done, Lock* lock, void (*f)(Arg), Arg arg) { |
| 94 // When *done == true: | 94 // When *done == true: |
| 95 // Also known as a load-load/load-store barrier, this acquire barrier make
s | 95 // Also known as a load-load/load-store barrier, this acquire barrier make
s |
| 96 // sure that anything we read from memory---in particular, memory written
by | 96 // sure that anything we read from memory---in particular, memory written
by |
| (...skipping 33 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 |