| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project 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 #include "src/base/platform/mutex.h" | 5 #include "src/base/platform/mutex.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 | 8 |
| 9 namespace v8 { | 9 namespace v8 { |
| 10 namespace base { | 10 namespace base { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 105 |
| 106 static V8_INLINE bool TryLockNativeHandle(PCRITICAL_SECTION cs) { | 106 static V8_INLINE bool TryLockNativeHandle(PCRITICAL_SECTION cs) { |
| 107 return TryEnterCriticalSection(cs); | 107 return TryEnterCriticalSection(cs); |
| 108 } | 108 } |
| 109 | 109 |
| 110 #endif // V8_OS_POSIX | 110 #endif // V8_OS_POSIX |
| 111 | 111 |
| 112 | 112 |
| 113 Mutex::Mutex() { | 113 Mutex::Mutex() { |
| 114 InitializeNativeHandle(&native_handle_); | 114 InitializeNativeHandle(&native_handle_); |
| 115 #ifdef DEBUG | 115 #if DCHECK_IS_ON |
| 116 level_ = 0; | 116 level_ = 0; |
| 117 #endif | 117 #endif |
| 118 } | 118 } |
| 119 | 119 |
| 120 | 120 |
| 121 Mutex::~Mutex() { | 121 Mutex::~Mutex() { |
| 122 DestroyNativeHandle(&native_handle_); | 122 DestroyNativeHandle(&native_handle_); |
| 123 DCHECK_EQ(0, level_); | 123 DCHECK_EQ(0, level_); |
| 124 } | 124 } |
| 125 | 125 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 140 if (!TryLockNativeHandle(&native_handle_)) { | 140 if (!TryLockNativeHandle(&native_handle_)) { |
| 141 return false; | 141 return false; |
| 142 } | 142 } |
| 143 AssertUnheldAndMark(); | 143 AssertUnheldAndMark(); |
| 144 return true; | 144 return true; |
| 145 } | 145 } |
| 146 | 146 |
| 147 | 147 |
| 148 RecursiveMutex::RecursiveMutex() { | 148 RecursiveMutex::RecursiveMutex() { |
| 149 InitializeRecursiveNativeHandle(&native_handle_); | 149 InitializeRecursiveNativeHandle(&native_handle_); |
| 150 #ifdef DEBUG | 150 #if DCHECK_IS_ON |
| 151 level_ = 0; | 151 level_ = 0; |
| 152 #endif | 152 #endif |
| 153 } | 153 } |
| 154 | 154 |
| 155 | 155 |
| 156 RecursiveMutex::~RecursiveMutex() { | 156 RecursiveMutex::~RecursiveMutex() { |
| 157 DestroyNativeHandle(&native_handle_); | 157 DestroyNativeHandle(&native_handle_); |
| 158 DCHECK_EQ(0, level_); | 158 DCHECK_EQ(0, level_); |
| 159 } | 159 } |
| 160 | 160 |
| 161 | 161 |
| 162 void RecursiveMutex::Lock() { | 162 void RecursiveMutex::Lock() { |
| 163 LockNativeHandle(&native_handle_); | 163 LockNativeHandle(&native_handle_); |
| 164 #ifdef DEBUG | 164 #if DCHECK_IS_ON |
| 165 DCHECK_LE(0, level_); | 165 DCHECK_LE(0, level_); |
| 166 level_++; | 166 level_++; |
| 167 #endif | 167 #endif |
| 168 } | 168 } |
| 169 | 169 |
| 170 | 170 |
| 171 void RecursiveMutex::Unlock() { | 171 void RecursiveMutex::Unlock() { |
| 172 #ifdef DEBUG | 172 #if DCHECK_IS_ON |
| 173 DCHECK_LT(0, level_); | 173 DCHECK_LT(0, level_); |
| 174 level_--; | 174 level_--; |
| 175 #endif | 175 #endif |
| 176 UnlockNativeHandle(&native_handle_); | 176 UnlockNativeHandle(&native_handle_); |
| 177 } | 177 } |
| 178 | 178 |
| 179 | 179 |
| 180 bool RecursiveMutex::TryLock() { | 180 bool RecursiveMutex::TryLock() { |
| 181 if (!TryLockNativeHandle(&native_handle_)) { | 181 if (!TryLockNativeHandle(&native_handle_)) { |
| 182 return false; | 182 return false; |
| 183 } | 183 } |
| 184 #ifdef DEBUG | 184 #if DCHECK_IS_ON |
| 185 DCHECK_LE(0, level_); | 185 DCHECK_LE(0, level_); |
| 186 level_++; | 186 level_++; |
| 187 #endif | 187 #endif |
| 188 return true; | 188 return true; |
| 189 } | 189 } |
| 190 | 190 |
| 191 } } // namespace v8::base | 191 } } // namespace v8::base |
| OLD | NEW |