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

Unified Diff: include/private/SkMutex.h

Issue 1417583005: Add lighter weight lock guards. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 2 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 | « no previous file | src/core/SkSharedMutex.h » ('j') | src/core/SkSharedMutex.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/private/SkMutex.h
diff --git a/include/private/SkMutex.h b/include/private/SkMutex.h
index c3e9919e52a98548d957ef10a727e1fd812aafb8..da44f648d0b17595b21ad32830e5cb52b8b46048 100644
--- a/include/private/SkMutex.h
+++ b/include/private/SkMutex.h
@@ -105,7 +105,21 @@ private:
Lock* fMutex;
};
+// 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 {
+public:
+ SkAutoTExclusive(Lock& lock) : fLock(lock) { lock.acquire(); }
+ ~SkAutoTExclusive() { fLock.release(); }
+private:
+ Lock &fLock;
+};
+
typedef SkAutoTAcquire<SkBaseMutex> SkAutoMutexAcquire;
#define SkAutoMutexAcquire(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexAcquire)
+typedef SkAutoTExclusive<SkMutex> SkAutoMutexExclusive;
+#define SkAutoMutexExclusive(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexExclusive)
+
#endif//SkMutex_DEFINED
« no previous file with comments | « no previous file | src/core/SkSharedMutex.h » ('j') | src/core/SkSharedMutex.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698