Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ppapi / utility / threading / lock.cc
blobee4bad70f9d5d9865db014fcc8f8bd5838ab55f3
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ppapi/utility/threading/lock.h"
7 namespace pp {
9 #ifdef WIN32 // Windows implementation for native plugins.
11 Lock::Lock() {
12 // The second parameter is the spin count; for short-held locks it avoids the
13 // contending thread from going to sleep which helps performance greatly.
14 ::InitializeCriticalSectionAndSpinCount(&os_lock_, 2000);
17 Lock::~Lock() {
18 ::DeleteCriticalSection(&os_lock_);
21 void Lock::Acquire() {
22 ::EnterCriticalSection(&os_lock_);
25 void Lock::Release() {
26 ::LeaveCriticalSection(&os_lock_);
29 #else // Posix implementation.
31 Lock::Lock() {
32 pthread_mutex_init(&os_lock_, NULL);
35 Lock::~Lock() {
36 pthread_mutex_destroy(&os_lock_);
39 void Lock::Acquire() {
40 pthread_mutex_lock(&os_lock_);
43 void Lock::Release() {
44 pthread_mutex_unlock(&os_lock_);
47 #endif
49 } // namespace pp