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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkAtomics.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPixelRef.cpp
diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp
index bfee3bb549149c88bfd2846eab0b8a32857ee613..dea8c8aed0ce9daa0f3977f779082b2a37d58a3e 100644
--- a/src/core/SkPixelRef.cpp
+++ b/src/core/SkPixelRef.cpp
@@ -207,9 +207,14 @@ bool SkPixelRef::onLockPixelsAreWritable() const {
uint32_t SkPixelRef::getGenerationID() const {
uint32_t id = fTaggedGenID.load();
if (0 == id) {
- id = next_gen_id();
- fTaggedGenID.store(id | 1u); // TODO(mtklein): should become a compare-and-swap
- SkASSERT(this->genIDIsUnique());
+ uint32_t next = next_gen_id() | 1u;
+ if (fTaggedGenID.compare_exchange(&id, next)) {
+ id = next; // There was no race or we won the race. fTaggedGenID is next now.
+ } else {
+ // We lost a race to set fTaggedGenID. compare_exchange() filled id with the winner.
+ }
+ // We can't quite SkASSERT(this->genIDIsUnique()). It could be non-unique
+ // if we got here via the else path (pretty unlikely, but possible).
}
return id & ~1u; // Mask off bottom unique bit.
}
« 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