summaryrefslogtreecommitdiffstats
path: root/base/synchronization/lock.h
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-23 22:19:29 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-23 22:19:29 +0000
commitba198cae91c60d1e0a3a5119bb4c812a33febd96 (patch)
tree2e0747c394f2d4d5e38a885b45850ce0a774f045 /base/synchronization/lock.h
parentbe0c0050e6df6f18447fba2a85f2b9a7770e1955 (diff)
downloadchromium_src-ba198cae91c60d1e0a3a5119bb4c812a33febd96.zip
chromium_src-ba198cae91c60d1e0a3a5119bb4c812a33febd96.tar.gz
chromium_src-ba198cae91c60d1e0a3a5119bb4c812a33febd96.tar.bz2
base: Cleanup: Simplify the declaration of Lock class.
This is the first step into merging Lock and LockImpl. The later will be merged into Lock when things get more clearer. BUG=283054 TEST=base_unittests --gtest_filter=LockTest.* R=darin@chromium.org, brettw@chromium.org Review URL: https://codereview.chromium.org/159283003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@252864 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/synchronization/lock.h')
-rw-r--r--base/synchronization/lock.h45
1 files changed, 13 insertions, 32 deletions
diff --git a/base/synchronization/lock.h b/base/synchronization/lock.h
index 7e8ffe7..ab5ee68 100644
--- a/base/synchronization/lock.h
+++ b/base/synchronization/lock.h
@@ -16,47 +16,29 @@ namespace base {
// AssertAcquired() method.
class BASE_EXPORT Lock {
public:
-#if defined(NDEBUG) // Optimized wrapper implementation
- 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. This must not be called
- // by a thread already holding the lock (what happens is undefined and an
- // assertion may fail).
- bool Try() { return lock_.Try(); }
-
- // Null implementation if not debug.
- void AssertAcquired() const {}
-#else
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
// acquire the lock a second time (while already holding it).
- void Acquire() {
- lock_.Lock();
- CheckUnheldAndMark();
- }
- void Release() {
- CheckHeldAndUnmark();
- lock_.Unlock();
- }
+ void Acquire();
- bool Try() {
- bool rv = lock_.Try();
- if (rv) {
- CheckUnheldAndMark();
- }
- return rv;
- }
+ void Release();
+ // If the lock is not held, take it and return true. If the lock is already
+ // held by another thread, immediately return false. This must not be called
+ // by a thread already holding the lock (what happens is undefined and an
+ // assertion may fail).
+ bool Try();
+
+#if !defined(NDEBUG)
void AssertAcquired() const;
-#endif // NDEBUG
+#else
+ void AssertAcquired() const {}
+#endif
+ private:
#if defined(OS_POSIX)
// The posix implementation of ConditionVariable needs to be able
// to see our lock and tweak our debugging counters, as it releases
@@ -68,7 +50,6 @@ class BASE_EXPORT Lock {
friend class WinVistaCondVar;
#endif
- private:
#if !defined(NDEBUG)
// Members and routines taking care of locks assertions.
// Note that this checks for recursive locks and allows them