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

Unified Diff: src/ports/SkMutex_pthread.h

Issue 313823004: Add assertHeld() to SkMutex. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: more Created 6 years, 6 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 | « src/pdf/SkPDFGraphicState.cpp ('k') | src/ports/SkMutex_win.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkMutex_pthread.h
diff --git a/src/ports/SkMutex_pthread.h b/src/ports/SkMutex_pthread.h
index d9f1ae301ef6b64107335281f604819a9b2bdb7b..1904140c4cc651f2c7b5bf3191a7c97e81f8591d 100644
--- a/src/ports/SkMutex_pthread.h
+++ b/src/ports/SkMutex_pthread.h
@@ -10,16 +10,6 @@
/** Posix pthread_mutex based mutex. */
-#ifdef SK_DEBUG_PTHREAD_MUTEX
-#include "SkTypes.h"
-#define SkDEBUGCODE_PTHREAD_MUTEX(code) code
-#else
-#define SkDEBUGCODE_PTHREAD_MUTEX(code)
-#ifndef SkDebugf
- void SkDebugf(const char format[], ...);
-#endif
-#endif
-
#include <errno.h>
#include <pthread.h>
@@ -28,9 +18,21 @@
// generation of a static initializer in the final machine code (and
// a corresponding static finalizer).
struct SkBaseMutex {
- void acquire() { pthread_mutex_lock(&fMutex); }
- void release() { pthread_mutex_unlock(&fMutex); }
+ void acquire() {
+ pthread_mutex_lock(&fMutex);
+ SkDEBUGCODE(fOwner = pthread_self();)
+ }
+ void release() {
+ this->assertHeld();
+ SkDEBUGCODE(fOwner = 0;)
+ pthread_mutex_unlock(&fMutex);
+ }
+ void assertHeld() {
+ SkASSERT(pthread_self() == fOwner);
+ }
+
pthread_mutex_t fMutex;
+ SkDEBUGCODE(pthread_t fOwner;)
};
// A normal mutex that requires to be initialized through normal C++ construction,
@@ -38,8 +40,8 @@ struct SkBaseMutex {
class SkMutex : public SkBaseMutex {
public:
SkMutex() {
- SkDEBUGCODE_PTHREAD_MUTEX(int status = )pthread_mutex_init(&fMutex, NULL);
- SkDEBUGCODE_PTHREAD_MUTEX(
+ SkDEBUGCODE(int status = )pthread_mutex_init(&fMutex, NULL);
+ SkDEBUGCODE(
if (status != 0) {
print_pthread_error(status);
SkASSERT(0 == status);
@@ -48,8 +50,8 @@ public:
}
~SkMutex() {
- SkDEBUGCODE_PTHREAD_MUTEX(int status = )pthread_mutex_destroy(&fMutex);
- SkDEBUGCODE_PTHREAD_MUTEX(
+ SkDEBUGCODE(int status = )pthread_mutex_destroy(&fMutex);
+ SkDEBUGCODE(
if (status != 0) {
print_pthread_error(status);
SkASSERT(0 == status);
@@ -78,10 +80,12 @@ private:
}
};
+#define SK_BASE_MUTEX_INIT { PTHREAD_MUTEX_INITIALIZER, SkDEBUGCODE(0) }
+
// Using POD-style initialization prevents the generation of a static initializer.
-#define SK_DECLARE_STATIC_MUTEX(name) static SkBaseMutex name = { PTHREAD_MUTEX_INITIALIZER }
+#define SK_DECLARE_STATIC_MUTEX(name) static SkBaseMutex name = SK_BASE_MUTEX_INIT
// Special case used when the static mutex must be available globally.
-#define SK_DECLARE_GLOBAL_MUTEX(name) SkBaseMutex name = { PTHREAD_MUTEX_INITIALIZER }
+#define SK_DECLARE_GLOBAL_MUTEX(name) SkBaseMutex name = SK_BASE_MUTEX_INIT
#endif
« no previous file with comments | « src/pdf/SkPDFGraphicState.cpp ('k') | src/ports/SkMutex_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698