RESTRICT AUTOMERGE: Make listener lists threadsafe with a mutex.
Bug: 124232283
Test: Infeasible
Cherry-pick of https://skia-review.googlesource.com/155060 in Skia
There were conflicts due the fact that pi-dev does not have commit
afa11586d782c7cb3e83b8af48023ff227349516 ("Make the SkPathRef
GenIDChangeListener ref counted") or
6c8d242b14355bf66c9137e9e4d6c7861d22168f ("Make atomic lists list for
bitmaps and paths" - an alternate fix for this issue) and some smaller
header file changes.
Change-Id: I7c2c5cd6603007d099169071a1b7d1a230c621bc
Merged-In: I91a8fbdd1b8fb4cf8b124ebdf17212c643058ef3
(cherry picked from commit bf999383abd128f8db32fc2f24606679280a5b7d)
diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h
index 49f0f97..52e679e 100644
--- a/include/core/SkPixelRef.h
+++ b/include/core/SkPixelRef.h
@@ -88,7 +88,7 @@
virtual void onChange() = 0;
};
- // Takes ownership of listener.
+ // Takes ownership of listener. Threadsafe.
void addGenIDChangeListener(GenIDChangeListener* listener);
// Call when this pixelref is part of the key to a resourcecache entry. This allows the cache
@@ -119,6 +119,7 @@
const uint32_t fStableID;
#endif
+ SkMutex fGenIDChangeListenersMutex;
SkTDArray<GenIDChangeListener*> fGenIDChangeListeners; // pointers are owned
// Set true by caches when they cache content that's derived from the current pixels.
diff --git a/include/private/SkPathRef.h b/include/private/SkPathRef.h
index b9b52d4..0a1c579 100644
--- a/include/private/SkPathRef.h
+++ b/include/private/SkPathRef.h
@@ -12,6 +12,7 @@
#include "../private/SkAtomics.h"
#include "../private/SkTDArray.h"
#include "SkMatrix.h"
+#include "SkMutex.h"
#include "SkPoint.h"
#include "SkRRect.h"
#include "SkRect.h"
@@ -311,7 +312,7 @@
virtual void onChange() = 0;
};
- void addGenIDChangeListener(GenIDChangeListener* listener);
+ void addGenIDChangeListener(GenIDChangeListener* listener); // Threadsafe
bool isValid() const;
SkDEBUGCODE(void validate() const { SkASSERT(this->isValid()); } )
@@ -538,6 +539,7 @@
mutable uint32_t fGenerationID;
SkDEBUGCODE(int32_t fEditorsAttached;) // assert that only one editor in use at any time.
+ SkMutex fGenIDChangeListenersMutex;
SkTDArray<GenIDChangeListener*> fGenIDChangeListeners; // pointers are owned
mutable uint8_t fBoundsIsDirty;
diff --git a/src/core/SkPathRef.cpp b/src/core/SkPathRef.cpp
index c710f71..a725f7e 100644
--- a/src/core/SkPathRef.cpp
+++ b/src/core/SkPathRef.cpp
@@ -670,11 +670,13 @@
delete listener;
return;
}
+ SkAutoMutexAcquire lock(fGenIDChangeListenersMutex);
*fGenIDChangeListeners.append() = listener;
}
// we need to be called *before* the genID gets changed or zerod
void SkPathRef::callGenIDChangeListeners() {
+ SkAutoMutexAcquire lock(fGenIDChangeListenersMutex);
for (int i = 0; i < fGenIDChangeListeners.count(); i++) {
fGenIDChangeListeners[i]->onChange();
}
diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp
index d5e9360..868ac8c 100644
--- a/src/core/SkPixelRef.cpp
+++ b/src/core/SkPixelRef.cpp
@@ -92,11 +92,13 @@
delete listener;
return;
}
+ SkAutoMutexAcquire lock(fGenIDChangeListenersMutex);
*fGenIDChangeListeners.append() = listener;
}
// we need to be called *before* the genID gets changed or zerod
void SkPixelRef::callGenIDChangeListeners() {
+ SkAutoMutexAcquire lock(fGenIDChangeListenersMutex);
// We don't invalidate ourselves if we think another SkPixelRef is sharing our genID.
if (this->genIDIsUnique()) {
for (int i = 0; i < fGenIDChangeListeners.count(); i++) {