Fri, 16 Jan 2015 04:50:19 +0100
Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32
michael@0 | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #include "base/synchronization/lock_impl.h" |
michael@0 | 6 | |
michael@0 | 7 | namespace base { |
michael@0 | 8 | namespace internal { |
michael@0 | 9 | |
michael@0 | 10 | LockImpl::LockImpl() { |
michael@0 | 11 | // The second parameter is the spin count, for short-held locks it avoid the |
michael@0 | 12 | // contending thread from going to sleep which helps performance greatly. |
michael@0 | 13 | ::InitializeCriticalSectionAndSpinCount(&native_handle_, 2000); |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | LockImpl::~LockImpl() { |
michael@0 | 17 | ::DeleteCriticalSection(&native_handle_); |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | bool LockImpl::Try() { |
michael@0 | 21 | if (::TryEnterCriticalSection(&native_handle_) != FALSE) { |
michael@0 | 22 | return true; |
michael@0 | 23 | } |
michael@0 | 24 | return false; |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | void LockImpl::Lock() { |
michael@0 | 28 | ::EnterCriticalSection(&native_handle_); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | void LockImpl::Unlock() { |
michael@0 | 32 | ::LeaveCriticalSection(&native_handle_); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | } // namespace internal |
michael@0 | 36 | } // namespace base |