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"
9 #ifdef WIN32 // Windows implementation for native plugins.
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);
18 ::DeleteCriticalSection(&os_lock_
);
21 void Lock::Acquire() {
22 ::EnterCriticalSection(&os_lock_
);
25 void Lock::Release() {
26 ::LeaveCriticalSection(&os_lock_
);
29 #else // Posix implementation.
32 pthread_mutex_init(&os_lock_
, NULL
);
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_
);