michael@0: // Copyright (c) 2011 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #include "base/synchronization/lock_impl.h" michael@0: michael@0: namespace base { michael@0: namespace internal { michael@0: michael@0: LockImpl::LockImpl() { michael@0: // The second parameter is the spin count, for short-held locks it avoid the michael@0: // contending thread from going to sleep which helps performance greatly. michael@0: ::InitializeCriticalSectionAndSpinCount(&native_handle_, 2000); michael@0: } michael@0: michael@0: LockImpl::~LockImpl() { michael@0: ::DeleteCriticalSection(&native_handle_); michael@0: } michael@0: michael@0: bool LockImpl::Try() { michael@0: if (::TryEnterCriticalSection(&native_handle_) != FALSE) { michael@0: return true; michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: void LockImpl::Lock() { michael@0: ::EnterCriticalSection(&native_handle_); michael@0: } michael@0: michael@0: void LockImpl::Unlock() { michael@0: ::LeaveCriticalSection(&native_handle_); michael@0: } michael@0: michael@0: } // namespace internal michael@0: } // namespace base