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

Unified Diff: src/ports/SkMutex_pthread.h

Issue 357473002: Tidy up fOwner in SkMutex_pthread.h. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 | « no previous file | no next file » | 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 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;
)
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698