Commit 370c7838 authored by boliu@chromium.org's avatar boliu@chromium.org

base: Enable lock dchecks with dchecks_always_on

Enable DCHECKs in Lock and ConditionVariable when compiled
with dchecks_always_on.

Note the correctness of DCHECKs relies on DCHECKs enabled
in both Lock and ConditionVariable. This CL keeps the
condition to enable DCHECKs in ConditionVariable the
same as Lock, to avoid any issues here.

BUG=

Review URL: https://codereview.chromium.org/403803004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284534 0039d316-1c4b-4281-b951-d872f2087c98
parent dac186fb
......@@ -104,7 +104,7 @@ class BASE_EXPORT ConditionVariable {
#elif defined(OS_POSIX)
pthread_cond_t condition_;
pthread_mutex_t* user_mutex_;
#if !defined(NDEBUG)
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
base::Lock* user_lock_; // Needed to adjust shadow lock state on wait.
#endif
......
......@@ -16,7 +16,7 @@ namespace base {
ConditionVariable::ConditionVariable(Lock* user_lock)
: user_mutex_(user_lock->lock_.native_handle())
#if !defined(NDEBUG)
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
, user_lock_(user_lock)
#endif
{
......@@ -48,12 +48,12 @@ ConditionVariable::~ConditionVariable() {
void ConditionVariable::Wait() {
base::ThreadRestrictions::AssertWaitAllowed();
#if !defined(NDEBUG)
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
user_lock_->CheckHeldAndUnmark();
#endif
int rv = pthread_cond_wait(&condition_, user_mutex_);
DCHECK_EQ(0, rv);
#if !defined(NDEBUG)
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
user_lock_->CheckUnheldAndMark();
#endif
}
......@@ -66,7 +66,7 @@ void ConditionVariable::TimedWait(const TimeDelta& max_time) {
relative_time.tv_nsec =
(usecs % Time::kMicrosecondsPerSecond) * Time::kNanosecondsPerMicrosecond;
#if !defined(NDEBUG)
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
user_lock_->CheckHeldAndUnmark();
#endif
......@@ -104,7 +104,7 @@ void ConditionVariable::TimedWait(const TimeDelta& max_time) {
#endif // OS_MACOSX
DCHECK(rv == 0 || rv == ETIMEDOUT);
#if !defined(NDEBUG)
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
user_lock_->CheckUnheldAndMark();
#endif
}
......
......@@ -99,7 +99,7 @@ void WinVistaCondVar::TimedWait(const TimeDelta& max_time) {
DWORD timeout = static_cast<DWORD>(max_time.InMilliseconds());
CRITICAL_SECTION* cs = user_lock_.lock_.native_handle();
#if !defined(NDEBUG)
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
user_lock_.CheckHeldAndUnmark();
#endif
......@@ -107,7 +107,7 @@ void WinVistaCondVar::TimedWait(const TimeDelta& max_time) {
DCHECK(GetLastError() != WAIT_TIMEOUT);
}
#if !defined(NDEBUG)
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
user_lock_.CheckUnheldAndMark();
#endif
}
......
......@@ -6,7 +6,7 @@
// is functionally a wrapper around the LockImpl class, so the only
// real intelligence in the class is in the debugging logic.
#if !defined(NDEBUG)
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
#include "base/synchronization/lock.h"
#include "base/logging.h"
......@@ -36,4 +36,4 @@ void Lock::CheckUnheldAndMark() {
} // namespace base
#endif // NDEBUG
#endif // !NDEBUG || DCHECK_ALWAYS_ON
......@@ -16,7 +16,8 @@ namespace base {
// AssertAcquired() method.
class BASE_EXPORT Lock {
public:
#if defined(NDEBUG) // Optimized wrapper implementation
#if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
// Optimized wrapper implementation
Lock() : lock_() {}
~Lock() {}
void Acquire() { lock_.Lock(); }
......@@ -55,7 +56,7 @@ class BASE_EXPORT Lock {
}
void AssertAcquired() const;
#endif // NDEBUG
#endif // NDEBUG && !DCHECK_ALWAYS_ON
#if defined(OS_POSIX)
// The posix implementation of ConditionVariable needs to be able
......@@ -69,7 +70,7 @@ class BASE_EXPORT Lock {
#endif
private:
#if !defined(NDEBUG)
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
// Members and routines taking care of locks assertions.
// Note that this checks for recursive locks and allows them
// if the variable is set. This is allowed by the underlying implementation
......@@ -81,7 +82,7 @@ class BASE_EXPORT Lock {
// All private data is implicitly protected by lock_.
// Be VERY careful to only access members under that lock.
base::PlatformThreadRef owning_thread_ref_;
#endif // NDEBUG
#endif // !NDEBUG || DCHECK_ALWAYS_ON
// Platform specific underlying lock implementation.
internal::LockImpl lock_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment