Assert lock/unlock/trylock sanity.
We rely on the underlying pthread code to behave sanely and this hasn't
always been true. Cost is a DCHECK, ie 0 for a regular build.
Change-Id: I888dde2ad14dd32ea306e09a6414e8e54ae02dd5
diff --git a/src/mutex.cc b/src/mutex.cc
index a2d9558..4760b2f 100644
--- a/src/mutex.cc
+++ b/src/mutex.cc
@@ -47,6 +47,7 @@
void Mutex::Lock() {
CHECK_MUTEX_CALL(pthread_mutex_lock, (&mutex_));
+ AssertHeld();
}
bool Mutex::TryLock() {
@@ -58,10 +59,12 @@
errno = result;
PLOG(FATAL) << "pthread_mutex_trylock failed for " << name_;
}
+ AssertHeld();
return true;
}
void Mutex::Unlock() {
+ AssertHeld();
CHECK_MUTEX_CALL(pthread_mutex_unlock, (&mutex_));
}