OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_SYNCHRONIZATION_LOCK_H_ | 5 #ifndef BASE_SYNCHRONIZATION_LOCK_H_ |
6 #define BASE_SYNCHRONIZATION_LOCK_H_ | 6 #define BASE_SYNCHRONIZATION_LOCK_H_ |
7 | 7 |
8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 // by a thread already holding the lock (what happens is undefined and an | 31 // by a thread already holding the lock (what happens is undefined and an |
32 // assertion may fail). | 32 // assertion may fail). |
33 bool Try() { return lock_.Try(); } | 33 bool Try() { return lock_.Try(); } |
34 | 34 |
35 // Null implementation if not debug. | 35 // Null implementation if not debug. |
36 void AssertAcquired() const {} | 36 void AssertAcquired() const {} |
37 #else | 37 #else |
38 Lock(); | 38 Lock(); |
39 ~Lock(); | 39 ~Lock(); |
40 | 40 |
41 // NOTE: Although windows critical sections support recursive locks, we do not | 41 // NOTE: We do not permit recursive locks and will commonly fire a DCHECK() if |
42 // allow this, and we will commonly fire a DCHECK() if a thread attempts to | 42 // a thread attempts to acquire the lock a second time (while already holding |
43 // acquire the lock a second time (while already holding it). | 43 // it). |
44 void Acquire() { | 44 void Acquire() { |
45 lock_.Lock(); | 45 lock_.Lock(); |
46 CheckUnheldAndMark(); | 46 CheckUnheldAndMark(); |
47 } | 47 } |
48 void Release() { | 48 void Release() { |
49 CheckHeldAndUnmark(); | 49 CheckHeldAndUnmark(); |
50 lock_.Unlock(); | 50 lock_.Unlock(); |
51 } | 51 } |
52 | 52 |
53 bool Try() { | 53 bool Try() { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 } | 127 } |
128 | 128 |
129 private: | 129 private: |
130 Lock& lock_; | 130 Lock& lock_; |
131 DISALLOW_COPY_AND_ASSIGN(AutoUnlock); | 131 DISALLOW_COPY_AND_ASSIGN(AutoUnlock); |
132 }; | 132 }; |
133 | 133 |
134 } // namespace base | 134 } // namespace base |
135 | 135 |
136 #endif // BASE_SYNCHRONIZATION_LOCK_H_ | 136 #endif // BASE_SYNCHRONIZATION_LOCK_H_ |
OLD | NEW |