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

Unified Diff: src/core/SkSharedMutex.h

Issue 1307863009: Add debug mode to shared mutex. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove space Created 5 years, 3 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 | « include/core/SkTypes.h ('k') | src/core/SkSharedMutex.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkSharedMutex.h
diff --git a/src/core/SkSharedMutex.h b/src/core/SkSharedMutex.h
index f3430040e38b51ee05ddb9d2915db44a30ff6ec3..9660adf0eb4084093801867033838db045cc40d3 100644
--- a/src/core/SkSharedMutex.h
+++ b/src/core/SkSharedMutex.h
@@ -11,9 +11,16 @@
#include "SkAtomics.h"
#include "SkSemaphore.h"
#include "SkTypes.h"
-
-// This is a shared lock implementation similar to pthreads rwlocks. This implementation is
-// cribbed from Preshing's article:
+
+#ifdef SK_DEBUG
+ #include "SkMutex.h"
+ #include "../private/SkUniquePtr.h"
+#endif // SK_DEBUG
+
+// There are two shared lock implementations one debug the other is high performance. They implement
+// an interface similar to pthread's rwlocks.
+// This is a shared lock implementation similar to pthreads rwlocks. The high performance
+// implementation is cribbed from Preshing's article:
// http://preshing.com/20150316/semaphores-are-surprisingly-versatile/
//
// This lock does not obey strict queue ordering. It will always alternate between readers and
@@ -29,11 +36,7 @@ public:
void release();
// Fail if exclusive is not held.
-#ifdef SK_DEBUG
void assertHeld() const;
-#else
- void assertHeld() const {}
-#endif
// Acquire lock for shared use.
void acquireShared();
@@ -42,17 +45,28 @@ public:
void releaseShared();
// Fail if shared lock not held.
-#ifdef SK_DEBUG
void assertHeldShared() const;
-#else
- void assertHeldShared() const {}
-#endif
private:
- SkAtomic<int32_t> fQueueCounts;
- SkSemaphore fSharedQueue;
+#ifdef SK_DEBUG
+ class ThreadIDSet;
+ skstd::unique_ptr<ThreadIDSet> fCurrentShared;
+ skstd::unique_ptr<ThreadIDSet> fWaitingExclusive;
+ skstd::unique_ptr<ThreadIDSet> fWaitingShared;
+ int fSharedQueueSelect{0};
+ mutable SkMutex fMu;
+ SkSemaphore fSharedQueue[2];
SkSemaphore fExclusiveQueue;
+#else
+ SkAtomic<int32_t> fQueueCounts;
+ SkSemaphore fSharedQueue;
+ SkSemaphore fExclusiveQueue;
+#endif // SK_DEBUG
};
+#ifndef SK_DEBUG
+inline void SkSharedMutex::assertHeld() const {};
+inline void SkSharedMutex::assertHeldShared() const {};
+#endif // SK_DEBUG
#endif // SkSharedLock_DEFINED
« no previous file with comments | « include/core/SkTypes.h ('k') | src/core/SkSharedMutex.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698