Index: include/private/SkMutex.h |
diff --git a/include/private/SkMutex.h b/include/private/SkMutex.h |
index 8c78e1205c8796261be4b19468338a00af8afdc5..d2a2d8230deb2503f211c190380badd351267d31 100644 |
--- a/include/private/SkMutex.h |
+++ b/include/private/SkMutex.h |
@@ -122,4 +122,40 @@ typedef SkAutoTAcquire<SkBaseMutex> SkAutoMutexAcquire; |
typedef SkAutoTExclusive<SkBaseMutex> SkAutoMutexExclusive; |
#define SkAutoMutexExclusive(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexExclusive) |
+#ifdef SK_DEBUG |
+// This is a debug tool to verify an object is only being used from one thread at a time |
+class SkSingleOwner { |
+public: |
+ SkSingleOwner() : fOwner(kIllegalThreadID), fReentranceCount(0) {} |
+ |
+ struct AutoEnforce { |
+ AutoEnforce(SkSingleOwner* so) : fSO(so) { fSO->enter(); } |
+ ~AutoEnforce() { fSO->exit(); } |
+ |
+ SkSingleOwner* fSO; |
+ }; |
+ |
+private: |
+ void enter() { |
+ SkAutoMutexAcquire lock(fMutex); |
+ SkThreadID self = SkGetThreadID(); |
+ SkASSERT(fOwner == self || fOwner == kIllegalThreadID); |
+ fReentranceCount++; |
+ fOwner = self; |
+ } |
+ |
+ void exit() { |
+ SkAutoMutexAcquire lock(fMutex); |
+ fReentranceCount--; |
+ if (fReentranceCount == 0) { |
+ fOwner = kIllegalThreadID; |
+ } |
+ } |
+ |
+ SkMutex fMutex; |
+ SkThreadID fOwner; // guarded by fMutex |
+ int fReentranceCount; // guarded by fMutex |
+}; |
+#endif |
+ |
#endif//SkMutex_DEFINED |