ipc/chromium/src/base/lock_impl_posix.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #include "base/lock_impl.h"
michael@0 6
michael@0 7 #include <errno.h>
michael@0 8
michael@0 9 #include "base/logging.h"
michael@0 10
michael@0 11 LockImpl::LockImpl() {
michael@0 12 #ifndef NDEBUG
michael@0 13 // In debug, setup attributes for lock error checking.
michael@0 14 pthread_mutexattr_t mta;
michael@0 15 int rv = pthread_mutexattr_init(&mta);
michael@0 16 DCHECK_EQ(rv, 0);
michael@0 17 rv = pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_ERRORCHECK);
michael@0 18 DCHECK_EQ(rv, 0);
michael@0 19 rv = pthread_mutex_init(&os_lock_, &mta);
michael@0 20 DCHECK_EQ(rv, 0);
michael@0 21 rv = pthread_mutexattr_destroy(&mta);
michael@0 22 DCHECK_EQ(rv, 0);
michael@0 23 #else
michael@0 24 // In release, go with the default lock attributes.
michael@0 25 pthread_mutex_init(&os_lock_, NULL);
michael@0 26 #endif
michael@0 27 }
michael@0 28
michael@0 29 LockImpl::~LockImpl() {
michael@0 30 int rv = pthread_mutex_destroy(&os_lock_);
michael@0 31 DCHECK_EQ(rv, 0);
michael@0 32 }
michael@0 33
michael@0 34 bool LockImpl::Try() {
michael@0 35 int rv = pthread_mutex_trylock(&os_lock_);
michael@0 36 DCHECK(rv == 0 || rv == EBUSY);
michael@0 37 return rv == 0;
michael@0 38 }
michael@0 39
michael@0 40 void LockImpl::Lock() {
michael@0 41 int rv = pthread_mutex_lock(&os_lock_);
michael@0 42 DCHECK_EQ(rv, 0);
michael@0 43 }
michael@0 44
michael@0 45 void LockImpl::Unlock() {
michael@0 46 int rv = pthread_mutex_unlock(&os_lock_);
michael@0 47 DCHECK_EQ(rv, 0);
michael@0 48 }

mercurial