security/sandbox/chromium/base/synchronization/lock_impl_win.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/sandbox/chromium/base/synchronization/lock_impl_win.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,36 @@
     1.4 +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#include "base/synchronization/lock_impl.h"
     1.9 +
    1.10 +namespace base {
    1.11 +namespace internal {
    1.12 +
    1.13 +LockImpl::LockImpl() {
    1.14 +  // The second parameter is the spin count, for short-held locks it avoid the
    1.15 +  // contending thread from going to sleep which helps performance greatly.
    1.16 +  ::InitializeCriticalSectionAndSpinCount(&native_handle_, 2000);
    1.17 +}
    1.18 +
    1.19 +LockImpl::~LockImpl() {
    1.20 +  ::DeleteCriticalSection(&native_handle_);
    1.21 +}
    1.22 +
    1.23 +bool LockImpl::Try() {
    1.24 +  if (::TryEnterCriticalSection(&native_handle_) != FALSE) {
    1.25 +    return true;
    1.26 +  }
    1.27 +  return false;
    1.28 +}
    1.29 +
    1.30 +void LockImpl::Lock() {
    1.31 +  ::EnterCriticalSection(&native_handle_);
    1.32 +}
    1.33 +
    1.34 +void LockImpl::Unlock() {
    1.35 +  ::LeaveCriticalSection(&native_handle_);
    1.36 +}
    1.37 +
    1.38 +}  // namespace internal
    1.39 +}  // namespace base

mercurial