Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Side by Side Diff: ppapi/utility/threading/lock.cc

Issue 10696157: Add support for threadsafe completion callback factory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "ppapi/utility/threading/lock.h"
6
7 namespace pp {
8
9 #ifdef WIN32 // Windows implementation for native plugins.
10
11 Lock::Lock() {
12 // The second parameter is the spin count, for short-held locks it avoid the
viettrungluu 2012/07/10 22:47:58 s/,/:/ (or a semicolon, or a period, but not a com
13 // contending thread from going to sleep which helps performance greatly.
14 ::InitializeCriticalSectionAndSpinCount(&os_lock_, 2000);
15 }
16
17 Lock::~Lock() {
18 ::DeleteCriticalSection(&os_lock_);
19 }
20
21 void Lock::Acquire() {
22 ::EnterCriticalSection(&os_lock_);
23 }
24
25 void Lock::Release() {
26 ::LeaveCriticalSection(&os_lock_);
27 }
28
29 #else // Posix implementation.
30
31 Lock::Lock() {
32 pthread_mutex_init(&os_lock_, NULL);
33 }
34
35 Lock::~Lock() {
36 pthread_mutex_destroy(&os_lock_);
37 }
38
39 void Lock::Acquire() {
40 pthread_mutex_lock(&os_lock_);
41 }
42
43 void Lock::Release() {
44 pthread_mutex_unlock(&os_lock_);
45 }
46
47 #endif
48
49 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698