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

Side by Side Diff: third_party/libphonenumber/cpp/src/base/synchronization/lock_impl_posix.cc

Issue 6803005: Autofill phone number enhancements and integration of Phone Number Util Library: part 1 (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 "base/synchronization/lock_impl.h"
6
7 #include <errno.h>
8
9 #include "base/logging.h"
10
11 namespace base {
12 namespace internal {
13
14 LockImpl::LockImpl() {
15 #ifndef NDEBUG
16 // In debug, setup attributes for lock error checking.
17 pthread_mutexattr_t mta;
18 int rv = pthread_mutexattr_init(&mta);
19 DCHECK_EQ(rv, 0);
20 rv = pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_ERRORCHECK);
21 DCHECK_EQ(rv, 0);
22 rv = pthread_mutex_init(&os_lock_, &mta);
23 DCHECK_EQ(rv, 0);
24 rv = pthread_mutexattr_destroy(&mta);
25 DCHECK_EQ(rv, 0);
26 #else
27 // In release, go with the default lock attributes.
28 pthread_mutex_init(&os_lock_, NULL);
29 #endif
30 }
31
32 LockImpl::~LockImpl() {
33 int rv = pthread_mutex_destroy(&os_lock_);
34 DCHECK_EQ(rv, 0);
35 }
36
37 bool LockImpl::Try() {
38 int rv = pthread_mutex_trylock(&os_lock_);
39 DCHECK(rv == 0 || rv == EBUSY);
40 return rv == 0;
41 }
42
43 void LockImpl::Lock() {
44 int rv = pthread_mutex_lock(&os_lock_);
45 DCHECK_EQ(rv, 0);
46 }
47
48 void LockImpl::Unlock() {
49 int rv = pthread_mutex_unlock(&os_lock_);
50 DCHECK_EQ(rv, 0);
51 }
52
53 } // namespace internal
54 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698