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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 bool rv = lock_.Try(); | 54 bool rv = lock_.Try(); |
55 if (rv) { | 55 if (rv) { |
56 CheckUnheldAndMark(); | 56 CheckUnheldAndMark(); |
57 } | 57 } |
58 return rv; | 58 return rv; |
59 } | 59 } |
60 | 60 |
61 void AssertAcquired() const; | 61 void AssertAcquired() const; |
62 #endif // DCHECK_IS_ON() | 62 #endif // DCHECK_IS_ON() |
63 | 63 |
64 #if defined(OS_POSIX) | 64 #if defined(OS_POSIX) || defined(OS_WIN) |
65 // The posix implementation of ConditionVariable needs to be able | 65 // Both Windows and POSIX implementations of ConditionVariable need to be |
66 // to see our lock and tweak our debugging counters, as it releases | 66 // able to see our lock and tweak our debugging counters, as they release and |
67 // and acquires locks inside of pthread_cond_{timed,}wait. | 67 // acquire locks inside of their condition variable APIs. |
68 friend class ConditionVariable; | 68 friend class ConditionVariable; |
69 #elif defined(OS_WIN) | |
70 // The Windows Vista implementation of ConditionVariable needs the | |
71 // native handle of the critical section. | |
72 friend class WinVistaCondVar; | |
73 #endif | 69 #endif |
74 | 70 |
75 private: | 71 private: |
76 #if DCHECK_IS_ON() | 72 #if DCHECK_IS_ON() |
77 // Members and routines taking care of locks assertions. | 73 // Members and routines taking care of locks assertions. |
78 // Note that this checks for recursive locks and allows them | 74 // Note that this checks for recursive locks and allows them |
79 // if the variable is set. This is allowed by the underlying implementation | 75 // if the variable is set. This is allowed by the underlying implementation |
80 // on windows but not on Posix, so we're doing unneeded checks on Posix. | 76 // on windows but not on Posix, so we're doing unneeded checks on Posix. |
81 // It's worth it to share the code. | 77 // It's worth it to share the code. |
82 void CheckHeldAndUnmark(); | 78 void CheckHeldAndUnmark(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 } | 127 } |
132 | 128 |
133 private: | 129 private: |
134 Lock& lock_; | 130 Lock& lock_; |
135 DISALLOW_COPY_AND_ASSIGN(AutoUnlock); | 131 DISALLOW_COPY_AND_ASSIGN(AutoUnlock); |
136 }; | 132 }; |
137 | 133 |
138 } // namespace base | 134 } // namespace base |
139 | 135 |
140 #endif // BASE_SYNCHRONIZATION_LOCK_H_ | 136 #endif // BASE_SYNCHRONIZATION_LOCK_H_ |
OLD | NEW |