Index: include/private/SkMutex.h |
diff --git a/include/private/SkMutex.h b/include/private/SkMutex.h |
index 3b0e1c47ca16e34cbeeb6e2b7b3b12d006815670..7cfdb1132c2f97a1795abc2728b0dcdbbccb3232 100644 |
--- a/include/private/SkMutex.h |
+++ b/include/private/SkMutex.h |
@@ -44,60 +44,50 @@ public: |
~SkMutex() { fSemaphore.cleanup(); } |
}; |
-template <typename Lock> |
-class SkAutoTAcquire : SkNoncopyable { |
+class SkAutoMutexAcquire { |
public: |
- explicit SkAutoTAcquire(Lock& mutex) : fMutex(&mutex) { |
- SkASSERT(fMutex != nullptr); |
- mutex.acquire(); |
- } |
- |
- explicit SkAutoTAcquire(Lock* mutex) : fMutex(mutex) { |
+ template <typename T> |
+ SkAutoMutexAcquire(T* mutex) : fMutex(mutex) { |
if (mutex) { |
mutex->acquire(); |
} |
+ fRelease = [](void* mutex) { ((T*)mutex)->release(); }; |
} |
- /** If the mutex has not been released, release it now. */ |
- ~SkAutoTAcquire() { |
- if (fMutex) { |
- fMutex->release(); |
- } |
- } |
+ template <typename T> |
+ SkAutoMutexAcquire(T& mutex) : SkAutoMutexAcquire(&mutex) {} |
+ |
+ ~SkAutoMutexAcquire() { this->release(); } |
- /** If the mutex has not been released, release it now. */ |
void release() { |
if (fMutex) { |
- fMutex->release(); |
- fMutex = nullptr; |
+ fRelease(fMutex); |
} |
- } |
- |
- /** Assert that we're holding the mutex. */ |
- void assertHeld() { |
- SkASSERT(fMutex); |
- fMutex->assertHeld(); |
+ fMutex = nullptr; |
} |
private: |
- Lock* fMutex; |
+ void* fMutex; |
+ void (*fRelease)(void*); |
}; |
+#define SkAutoMutexAcquire(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexAcquire) |
-// SkAutoTExclusive is a lighter weight version of SkAutoTAcquire. It assumes that there is a valid |
-// mutex, thus removing the check for the null pointer. |
-template <typename Lock> |
-class SkAutoTExclusive { |
+// SkAutoExclusive is a lighter weight version of SkAutoMutexAcquire. |
+// It assumes that there is a valid mutex, obviating the null check. |
+class SkAutoExclusive { |
public: |
- SkAutoTExclusive(Lock& lock) : fLock(lock) { lock.acquire(); } |
- ~SkAutoTExclusive() { fLock.release(); } |
-private: |
- Lock &fLock; |
-}; |
+ template <typename T> |
+ SkAutoExclusive(T& mutex) : fMutex(&mutex) { |
+ mutex.acquire(); |
-typedef SkAutoTAcquire<SkBaseMutex> SkAutoMutexAcquire; |
-#define SkAutoMutexAcquire(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexAcquire) |
+ fRelease = [](void* mutex) { ((T*)mutex)->release(); }; |
+ } |
+ ~SkAutoExclusive() { fRelease(fMutex); } |
-typedef SkAutoTExclusive<SkBaseMutex> SkAutoMutexExclusive; |
-#define SkAutoMutexExclusive(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexExclusive) |
+private: |
+ void* fMutex; |
+ void (*fRelease)(void*); |
+}; |
+#define SkAutoExclusive(...) SK_REQUIRE_LOCAL_VAR(SkAutoExclusive) |
#endif//SkMutex_DEFINED |