| 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/synchronization/lock_impl.h" | 9 #include "base/synchronization/lock_impl.h" |
| 10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // If the lock is not held, take it and return true. If the lock is already | 25 // If the lock is not held, take it and return true. If the lock is already |
| 26 // held by another thread, immediately return false. This must not be called | 26 // held by another thread, immediately return false. This must not be called |
| 27 // by a thread already holding the lock (what happens is undefined and an | 27 // by a thread already holding the lock (what happens is undefined and an |
| 28 // assertion may fail). | 28 // assertion may fail). |
| 29 bool Try() { return lock_.Try(); } | 29 bool Try() { return lock_.Try(); } |
| 30 | 30 |
| 31 // Null implementation if not debug. | 31 // Null implementation if not debug. |
| 32 void AssertAcquired() const {} | 32 void AssertAcquired() const {} |
| 33 #else | 33 #else |
| 34 Lock(); | 34 Lock(); |
| 35 ~Lock() {} | 35 ~Lock(); |
| 36 | 36 |
| 37 // NOTE: Although windows critical sections support recursive locks, we do not | 37 // NOTE: Although windows critical sections support recursive locks, we do not |
| 38 // allow this, and we will commonly fire a DCHECK() if a thread attempts to | 38 // allow this, and we will commonly fire a DCHECK() if a thread attempts to |
| 39 // acquire the lock a second time (while already holding it). | 39 // acquire the lock a second time (while already holding it). |
| 40 void Acquire() { | 40 void Acquire() { |
| 41 lock_.Lock(); | 41 lock_.Lock(); |
| 42 CheckUnheldAndMark(); | 42 CheckUnheldAndMark(); |
| 43 } | 43 } |
| 44 void Release() { | 44 void Release() { |
| 45 CheckHeldAndUnmark(); | 45 CheckHeldAndUnmark(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 } | 125 } |
| 126 | 126 |
| 127 private: | 127 private: |
| 128 Lock& lock_; | 128 Lock& lock_; |
| 129 DISALLOW_COPY_AND_ASSIGN(AutoUnlock); | 129 DISALLOW_COPY_AND_ASSIGN(AutoUnlock); |
| 130 }; | 130 }; |
| 131 | 131 |
| 132 } // namespace base | 132 } // namespace base |
| 133 | 133 |
| 134 #endif // BASE_SYNCHRONIZATION_LOCK_H_ | 134 #endif // BASE_SYNCHRONIZATION_LOCK_H_ |
| OLD | NEW |