Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(536)

Side by Side Diff: src/core/SkPixelRef.cpp

Issue 956013002: fix race to set the new gen ID (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkAtomics.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 #include "SkBitmapCache.h" 8 #include "SkBitmapCache.h"
9 #include "SkPixelRef.h" 9 #include "SkPixelRef.h"
10 #include "SkThread.h" 10 #include "SkThread.h"
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 return this->onLockPixelsAreWritable(); 200 return this->onLockPixelsAreWritable();
201 } 201 }
202 202
203 bool SkPixelRef::onLockPixelsAreWritable() const { 203 bool SkPixelRef::onLockPixelsAreWritable() const {
204 return true; 204 return true;
205 } 205 }
206 206
207 uint32_t SkPixelRef::getGenerationID() const { 207 uint32_t SkPixelRef::getGenerationID() const {
208 uint32_t id = fTaggedGenID.load(); 208 uint32_t id = fTaggedGenID.load();
209 if (0 == id) { 209 if (0 == id) {
210 id = next_gen_id(); 210 uint32_t next = next_gen_id() | 1u;
211 fTaggedGenID.store(id | 1u); // TODO(mtklein): should become a compare- and-swap 211 if (fTaggedGenID.compare_exchange(&id, next)) {
212 SkASSERT(this->genIDIsUnique()); 212 id = next; // There was no race or we won the race. fTaggedGenID i s next now.
213 } else {
214 // We lost a race to set fTaggedGenID. compare_exchange() filled id with the winner.
215 }
216 // We can't quite SkASSERT(this->genIDIsUnique()). It could be non-uniqu e
217 // if we got here via the else path (pretty unlikely, but possible).
213 } 218 }
214 return id & ~1u; // Mask off bottom unique bit. 219 return id & ~1u; // Mask off bottom unique bit.
215 } 220 }
216 221
217 void SkPixelRef::addGenIDChangeListener(GenIDChangeListener* listener) { 222 void SkPixelRef::addGenIDChangeListener(GenIDChangeListener* listener) {
218 if (NULL == listener || !this->genIDIsUnique()) { 223 if (NULL == listener || !this->genIDIsUnique()) {
219 // No point in tracking this if we're not going to call it. 224 // No point in tracking this if we're not going to call it.
220 SkDELETE(listener); 225 SkDELETE(listener);
221 return; 226 return;
222 } 227 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 278
274 bool SkPixelRef::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy tes[3], 279 bool SkPixelRef::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy tes[3],
275 SkYUVColorSpace* colorSpace) { 280 SkYUVColorSpace* colorSpace) {
276 return false; 281 return false;
277 } 282 }
278 283
279 size_t SkPixelRef::getAllocatedSizeInBytes() const { 284 size_t SkPixelRef::getAllocatedSizeInBytes() const {
280 return 0; 285 return 0;
281 } 286 }
282 287
OLDNEW
« no previous file with comments | « include/core/SkAtomics.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698