Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(366)

Side by Side Diff: base/lock.h

Issue 42402: Test was examining a variable without first acquiring a required Lock.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/condition_variable_unittest.cc ('k') | base/lock_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_LOCK_H_ 5 #ifndef BASE_LOCK_H_
6 #define BASE_LOCK_H_ 6 #define BASE_LOCK_H_
7 7
8 #include "base/lock_impl.h" 8 #include "base/lock_impl.h"
9 9
10 // A convenient wrapper for an OS specific critical section. 10 // A convenient wrapper for an OS specific critical section.
11 11
12 class Lock { 12 class Lock {
13 public: 13 public:
14 Lock() : lock_() {} 14 Lock() : lock_() {}
15 ~Lock() {} 15 ~Lock() {}
16 void Acquire() { lock_.Lock(); } 16 void Acquire() { lock_.Lock(); }
17 void Release() { lock_.Unlock(); } 17 void Release() { lock_.Unlock(); }
18 // If the lock is not held, take it and return true. If the lock is already 18 // If the lock is not held, take it and return true. If the lock is already
19 // held by another thread, immediately return false. 19 // held by another thread, immediately return false.
20 bool Try() { return lock_.Try(); } 20 bool Try() { return lock_.Try(); }
21 21
22 // In debug builds this method checks that the lock has been acquired by the 22 // In debug builds this method checks that the lock has been acquired by the
23 // calling thread. If the lock has not been acquired, then the method 23 // calling thread. If the lock has not been acquired, then the method
24 // will DCHECK(). In non-debug builds, the LockImpl's implementation of 24 // will DCHECK(). In non-debug builds, the LockImpl's implementation of
25 // AssertAcquired() is an empty inline method. 25 // AssertAcquired() is an empty inline method.
26 void AssertAcquired() { return lock_.AssertAcquired(); } 26 void AssertAcquired() const { return lock_.AssertAcquired(); }
27 27
28 // Return the underlying lock implementation. 28 // Return the underlying lock implementation.
29 // TODO(awalker): refactor lock and condition variables so that this is 29 // TODO(awalker): refactor lock and condition variables so that this is
30 // unnecessary. 30 // unnecessary.
31 LockImpl* lock_impl() { return &lock_; } 31 LockImpl* lock_impl() { return &lock_; }
32 32
33 private: 33 private:
34 LockImpl lock_; // Platform specific underlying lock implementation. 34 LockImpl lock_; // Platform specific underlying lock implementation.
35 35
36 DISALLOW_COPY_AND_ASSIGN(Lock); 36 DISALLOW_COPY_AND_ASSIGN(Lock);
(...skipping 29 matching lines...) Expand all
66 ~AutoUnlock() { 66 ~AutoUnlock() {
67 lock_.Acquire(); 67 lock_.Acquire();
68 } 68 }
69 69
70 private: 70 private:
71 Lock& lock_; 71 Lock& lock_;
72 DISALLOW_COPY_AND_ASSIGN(AutoUnlock); 72 DISALLOW_COPY_AND_ASSIGN(AutoUnlock);
73 }; 73 };
74 74
75 #endif // BASE_LOCK_H_ 75 #endif // BASE_LOCK_H_
OLDNEW
« no previous file with comments | « base/condition_variable_unittest.cc ('k') | base/lock_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698