Index: include/private/SkMutex.h |
diff --git a/include/private/SkMutex.h b/include/private/SkMutex.h |
index 8c78e1205c8796261be4b19468338a00af8afdc5..db8aefe9f580fba3df0ace5c7396159cc92394aa 100644 |
--- a/include/private/SkMutex.h |
+++ b/include/private/SkMutex.h |
@@ -54,6 +54,46 @@ struct SkBaseMutex { |
SkDEBUGCODE(SkThreadID fOwner;) |
}; |
+#ifdef SK_DEBUG |
+// This is a slow recursive mutex for debug purposes only |
+struct SkRecursiveMutex { |
+ SkRecursiveMutex () { |
+ fSemaphore = SK_MUTEX_SEMAPHORE_INIT; |
+ fOwner = kIllegalThreadID; |
+ fAcquireCount = 0; |
+ } |
+ ~SkRecursiveMutex () { fSemaphore.deleteSemaphore(); } |
+ |
+ void acquire() { |
+ if (fOwner != SkGetThreadID()) { |
+ fSemaphore.wait(); |
+ } |
+ fAcquireCount++; |
+ fOwner = SkGetThreadID(); |
+ } |
+ |
+ void release() { |
+ this->assertHeld(); |
+ if (1 == fAcquireCount--) { |
+ fOwner = kIllegalThreadID; |
+ fSemaphore.signal(); |
+ } |
+ } |
+ |
+ void assertHeld() { |
+ SkASSERT(fOwner == SkGetThreadID()); |
+ } |
+ |
+ void assertNotHeld() { |
+ SkASSERT(kIllegalThreadID == fOwner); |
+ } |
+ |
+ SkBaseSemaphore fSemaphore; |
+ SkThreadID fOwner; |
+ uint32_t fAcquireCount; |
+}; |
+#endif |
+ |
// This needs to use subclassing instead of encapsulation to make SkAutoMutexAcquire to work. |
class SkMutex : public SkBaseMutex { |
public: |