Index: src/ports/SkMutex_pthread.h |
diff --git a/src/ports/SkMutex_pthread.h b/src/ports/SkMutex_pthread.h |
index 662e549f12e65dd29cc6cd2b632327e8a026afea..f71016b31e88a28b3cc1932a2e4bf1d0f0c93abd 100644 |
--- a/src/ports/SkMutex_pthread.h |
+++ b/src/ports/SkMutex_pthread.h |
@@ -13,23 +13,27 @@ |
#include <errno.h> |
#include <pthread.h> |
+// This isn't technically portable, but on Linux and Android pthread_t is some sort of int, and |
+// on Darwin it's a pointer. So assuming pthread_self() never returns 0, it works as a sentinel. |
+SkDEBUGCODE(static const pthread_t kNoOwner = 0;) |
+ |
// A SkBaseMutex is a POD structure that can be directly initialized |
// at declaration time with SK_DECLARE_STATIC/GLOBAL_MUTEX. This avoids the |
// generation of a static initializer in the final machine code (and |
// a corresponding static finalizer). |
struct SkBaseMutex { |
void acquire() { |
- SkASSERT(fOwner != pthread_self()); // SkMutex is not re-entrant |
+ SkASSERT(0 == pthread_equal(fOwner, pthread_self())); // SkMutex is not re-entrant |
pthread_mutex_lock(&fMutex); |
SkDEBUGCODE(fOwner = pthread_self();) |
} |
void release() { |
this->assertHeld(); |
- SkDEBUGCODE(fOwner = 0;) |
+ SkDEBUGCODE(fOwner = kNoOwner;) |
pthread_mutex_unlock(&fMutex); |
} |
void assertHeld() { |
- SkASSERT(pthread_self() == fOwner); |
+ SkASSERT(0 != pthread_equal(fOwner, pthread_self())); |
} |
pthread_mutex_t fMutex; |
@@ -47,6 +51,7 @@ public: |
print_pthread_error(status); |
SkASSERT(0 == status); |
} |
+ fOwner = kNoOwner; |
) |
} |