| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "base/lock_impl.h" | 5 #include "base/lock_impl.h" |
| 6 #include "base/logging.h" | |
| 7 | 6 |
| 8 LockImpl::LockImpl() { | 7 LockImpl::LockImpl() { |
| 9 // The second parameter is the spin count, for short-held locks it avoid the | 8 // The second parameter is the spin count, for short-held locks it avoid the |
| 10 // contending thread from going to sleep which helps performance greatly. | 9 // contending thread from going to sleep which helps performance greatly. |
| 11 ::InitializeCriticalSectionAndSpinCount(&os_lock_, 2000); | 10 ::InitializeCriticalSectionAndSpinCount(&os_lock_, 2000); |
| 12 } | 11 } |
| 13 | 12 |
| 14 LockImpl::~LockImpl() { | 13 LockImpl::~LockImpl() { |
| 15 ::DeleteCriticalSection(&os_lock_); | 14 ::DeleteCriticalSection(&os_lock_); |
| 16 } | 15 } |
| 17 | 16 |
| 18 bool LockImpl::Try() { | 17 bool LockImpl::Try() { |
| 19 if (::TryEnterCriticalSection(&os_lock_) != FALSE) { | 18 if (::TryEnterCriticalSection(&os_lock_) != FALSE) { |
| 20 return true; | 19 return true; |
| 21 } | 20 } |
| 22 return false; | 21 return false; |
| 23 } | 22 } |
| 24 | 23 |
| 25 void LockImpl::Lock() { | 24 void LockImpl::Lock() { |
| 26 ::EnterCriticalSection(&os_lock_); | 25 ::EnterCriticalSection(&os_lock_); |
| 27 } | 26 } |
| 28 | 27 |
| 29 void LockImpl::Unlock() { | 28 void LockImpl::Unlock() { |
| 30 ::LeaveCriticalSection(&os_lock_); | 29 ::LeaveCriticalSection(&os_lock_); |
| 31 } | 30 } |
| 32 | |
| OLD | NEW |