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.
5 #include "base/synchronization/lock_impl.h"
9 #include "base/logging.h"
14 LockImpl::LockImpl() {
16 // In debug, setup attributes for lock error checking.
17 pthread_mutexattr_t mta
;
18 int rv
= pthread_mutexattr_init(&mta
);
20 rv
= pthread_mutexattr_settype(&mta
, PTHREAD_MUTEX_ERRORCHECK
);
22 rv
= pthread_mutex_init(&os_lock_
, &mta
);
24 rv
= pthread_mutexattr_destroy(&mta
);
27 // In release, go with the default lock attributes.
28 pthread_mutex_init(&os_lock_
, NULL
);
32 LockImpl::~LockImpl() {
33 int rv
= pthread_mutex_destroy(&os_lock_
);
37 bool LockImpl::Try() {
38 int rv
= pthread_mutex_trylock(&os_lock_
);
39 DCHECK(rv
== 0 || rv
== EBUSY
);
43 void LockImpl::Lock() {
44 int rv
= pthread_mutex_lock(&os_lock_
);
48 void LockImpl::Unlock() {
49 int rv
= pthread_mutex_unlock(&os_lock_
);
53 } // namespace internal