diff options
Diffstat (limited to 'base/synchronization')
-rw-r--r-- | base/synchronization/lock.cc | 11 | ||||
-rw-r--r-- | base/synchronization/lock.h | 2 |
2 files changed, 10 insertions, 3 deletions
diff --git a/base/synchronization/lock.cc b/base/synchronization/lock.cc index 6445ce8..49efbe9 100644 --- a/base/synchronization/lock.cc +++ b/base/synchronization/lock.cc @@ -13,9 +13,16 @@ namespace base { +const PlatformThreadId kNoThreadId = static_cast<PlatformThreadId>(0); + Lock::Lock() : lock_() { owned_by_thread_ = false; - owning_thread_id_ = static_cast<PlatformThreadId>(0); + owning_thread_id_ = kNoThreadId; +} + +Lock::~Lock() { + DCHECK(!owned_by_thread_); + DCHECK_EQ(kNoThreadId, owning_thread_id_); } void Lock::AssertAcquired() const { @@ -27,7 +34,7 @@ void Lock::CheckHeldAndUnmark() { DCHECK(owned_by_thread_); DCHECK_EQ(owning_thread_id_, PlatformThread::CurrentId()); owned_by_thread_ = false; - owning_thread_id_ = static_cast<PlatformThreadId>(0); + owning_thread_id_ = kNoThreadId; } void Lock::CheckUnheldAndMark() { diff --git a/base/synchronization/lock.h b/base/synchronization/lock.h index 15de446..bec37fb 100644 --- a/base/synchronization/lock.h +++ b/base/synchronization/lock.h @@ -32,7 +32,7 @@ class BASE_EXPORT Lock { void AssertAcquired() const {} #else Lock(); - ~Lock() {} + ~Lock(); // NOTE: Although windows critical sections support recursive locks, we do not // allow this, and we will commonly fire a DCHECK() if a thread attempts to |