Tidy up fOwner in SkMutex_pthread.h.
- Initialize fOwner to kNoOwner in SkMutex::SkMutex. - Note that we're stretching the API with kNoOwner. - Use pthread_equal() instead of ==. BUG=387993 R=halcanary@google.com, mtklein@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/357473002
This commit is contained in:
parent
a8d2ffb1c2
commit
5a940b5cbb
@ -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;
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user