diff options
author | jar@google.com <jar@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-21 23:37:02 +0000 |
---|---|---|
committer | jar@google.com <jar@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-21 23:37:02 +0000 |
commit | 3cdb6a704df743d914e67850f909b497b7e5ad5c (patch) | |
tree | b343dae90fa83293846cfa1a58a6d2904fb81271 /base/lock.h | |
parent | 68c245d774ca1ef9c9b11ea352ed22ac8c5f939c (diff) | |
download | chromium_src-3cdb6a704df743d914e67850f909b497b7e5ad5c.zip chromium_src-3cdb6a704df743d914e67850f909b497b7e5ad5c.tar.gz chromium_src-3cdb6a704df743d914e67850f909b497b7e5ad5c.tar.bz2 |
Move windows specific lock-recursion-counter into windows impl file
Unix implementation of lock leaks the underlying lock_impl_ member
so that the condition variable implementation can directly acquire
and release the lock (without going through our abstract interface). This
causse the recursion counter to become incorrect on such platforms.
Windows uses an implementation of condition variables that uses our abstract
interface, and hence is the only implementation that can track the
recursion count (and besides... windows is the only platform that currently
allows recursive (multiple) acquisitions of a lock by a single thread.
I'll work on gracefully removing the depricated lock.cc
after I've landed this change.
r=cpu
Review URL: http://codereview.chromium.org/7660
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3703 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/lock.h')
-rw-r--r-- | base/lock.h | 29 |
1 files changed, 6 insertions, 23 deletions
diff --git a/base/lock.h b/base/lock.h index b43e6ef..49cb37a 100644 --- a/base/lock.h +++ b/base/lock.h @@ -8,24 +8,16 @@ #include "base/lock_impl.h" // A convenient wrapper for an OS specific critical section. -// -// 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 -// acquire the lock a second time (while already holding it). -// -// Complication: UnitTest for DeathTests catch DCHECK exceptions, so we need -// to write code assuming DCHECK will throw. This means we need to save any -// assertable value in a local until we can safely throw. class Lock { public: - Lock(); - ~Lock(); - void Acquire(); - void Release(); + Lock() : lock_() {} + ~Lock() {} + void Acquire() { lock_.Lock(); } + void Release() { lock_.Unlock(); } // If the lock is not held, take it and return true. If the lock is already // held by another thread, immediately return false. - bool Try(); + bool Try() { return lock_.Try(); } // Return the underlying lock implementation. // TODO(awalker): refactor lock and condition variables so that this is @@ -33,16 +25,7 @@ class Lock { LockImpl* lock_impl() { return &lock_; } private: - LockImpl lock_; // User-supplied underlying lock implementation. - -#ifndef NDEBUG - // All private data is implicitly protected by lock_. - // Be VERY careful to only access members under that lock. - int32 recursion_count_shadow_; - bool recursion_used_; // Allow debugging to continued after a DCHECK(). - int32 acquisition_count_; // Number of times lock was acquired. - int32 contention_count_; // Number of times there was contention. -#endif // NDEBUG + LockImpl lock_; // Platform specific underlying lock implementation. DISALLOW_COPY_AND_ASSIGN(Lock); }; |