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

Side by Side Diff: base/synchronization/lock_impl_posix.cc

Issue 1647803004: Move base to DEPS (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « base/synchronization/lock_impl.h ('k') | base/synchronization/lock_impl_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <string.h>
9
10 #include "base/logging.h"
11
12 namespace base {
13 namespace internal {
14
15 LockImpl::LockImpl() {
16 #ifndef NDEBUG
17 // In debug, setup attributes for lock error checking.
18 pthread_mutexattr_t mta;
19 int rv = pthread_mutexattr_init(&mta);
20 DCHECK_EQ(rv, 0) << ". " << strerror(rv);
21 rv = pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_ERRORCHECK);
22 DCHECK_EQ(rv, 0) << ". " << strerror(rv);
23 rv = pthread_mutex_init(&native_handle_, &mta);
24 DCHECK_EQ(rv, 0) << ". " << strerror(rv);
25 rv = pthread_mutexattr_destroy(&mta);
26 DCHECK_EQ(rv, 0) << ". " << strerror(rv);
27 #else
28 // In release, go with the default lock attributes.
29 pthread_mutex_init(&native_handle_, NULL);
30 #endif
31 }
32
33 LockImpl::~LockImpl() {
34 int rv = pthread_mutex_destroy(&native_handle_);
35 DCHECK_EQ(rv, 0) << ". " << strerror(rv);
36 }
37
38 bool LockImpl::Try() {
39 int rv = pthread_mutex_trylock(&native_handle_);
40 DCHECK(rv == 0 || rv == EBUSY) << ". " << strerror(rv);
41 return rv == 0;
42 }
43
44 void LockImpl::Lock() {
45 int rv = pthread_mutex_lock(&native_handle_);
46 DCHECK_EQ(rv, 0) << ". " << strerror(rv);
47 }
48
49 void LockImpl::Unlock() {
50 int rv = pthread_mutex_unlock(&native_handle_);
51 DCHECK_EQ(rv, 0) << ". " << strerror(rv);
52 }
53
54 } // namespace internal
55 } // namespace base
OLDNEW
« no previous file with comments | « base/synchronization/lock_impl.h ('k') | base/synchronization/lock_impl_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698