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

Unified Diff: include/private/SkMutex.h

Issue 1555953004: Create debug only SkSingleOwner (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add sentinels to GrContext Created 4 years, 11 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
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:
« no previous file with comments | « include/gpu/GrContext.h ('k') | src/gpu/GrContext.cpp » ('j') | src/gpu/GrContext.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698