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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 void AnnotateBenignRace(const char* file, int line, const volatile void* mem, co
nst char* desc); | 122 void AnnotateBenignRace(const char* file, int line, const volatile void* mem, co
nst char* desc); |
123 } | 123 } |
124 #define ANNOTATE_BENIGN_RACE(mem, desc) AnnotateBenignRace(__FILE__, __LINE__, m
em, desc) | 124 #define ANNOTATE_BENIGN_RACE(mem, desc) AnnotateBenignRace(__FILE__, __LINE__, m
em, desc) |
125 #else | 125 #else |
126 #define ANNOTATE_BENIGN_RACE(mem, desc) | 126 #define ANNOTATE_BENIGN_RACE(mem, desc) |
127 #endif | 127 #endif |
128 | 128 |
129 // This is our fast path, called all the time. We do really want it to be inlin
ed. | 129 // This is our fast path, called all the time. We do really want it to be inlin
ed. |
130 template <typename Arg> | 130 template <typename Arg> |
131 inline void SkOnce(SkOnceFlag* once, void (*f)(Arg), Arg arg) { | 131 inline void SkOnce(SkOnceFlag* once, void (*f)(Arg), Arg arg) { |
132 ANNOTATE_BENIGN_RACE(once->done, "Don't worry TSAN, we're sure this is safe.
"); | 132 ANNOTATE_BENIGN_RACE(&(once->done), "Don't worry TSAN, we're sure this is sa
fe."); |
133 if (!once->done) { | 133 if (!once->done) { |
134 sk_once_slow(once, f, arg); | 134 sk_once_slow(once, f, arg); |
135 } | 135 } |
136 // Also known as a load-load/load-store barrier, this acquire barrier makes | 136 // Also known as a load-load/load-store barrier, this acquire barrier makes |
137 // sure that anything we read from memory---in particular, memory written by | 137 // sure that anything we read from memory---in particular, memory written by |
138 // calling f(arg)---is at least as current as the value we read from once->d
one. | 138 // calling f(arg)---is at least as current as the value we read from once->d
one. |
139 // | 139 // |
140 // In version control terms, this is a lot like saying "sync up to the | 140 // In version control terms, this is a lot like saying "sync up to the |
141 // commit where we wrote once->done = true". | 141 // commit where we wrote once->done = true". |
142 // | 142 // |
143 // The release barrier in sk_once_slow guaranteed that once->done = true | 143 // The release barrier in sk_once_slow guaranteed that once->done = true |
144 // happens after f(arg), so by syncing to once->done = true here we're | 144 // happens after f(arg), so by syncing to once->done = true here we're |
145 // forcing ourselves to also wait until the effects of f(arg) are readble. | 145 // forcing ourselves to also wait until the effects of f(arg) are readble. |
146 acquire_barrier(); | 146 acquire_barrier(); |
147 } | 147 } |
148 | 148 |
149 #undef ANNOTATE_BENIGN_RACE | 149 #undef ANNOTATE_BENIGN_RACE |
150 | 150 |
151 #endif // SkOnce_DEFINED | 151 #endif // SkOnce_DEFINED |
OLD | NEW |