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.

     1 // Copyright (c) 2006-2008 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/lock_impl.h"
     7 #include <errno.h>
     9 #include "base/logging.h"
    11 LockImpl::LockImpl() {
    12 #ifndef NDEBUG
    13   // In debug, setup attributes for lock error checking.
    14   pthread_mutexattr_t mta;
    15   int rv = pthread_mutexattr_init(&mta);
    16   DCHECK_EQ(rv, 0);
    17   rv = pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_ERRORCHECK);
    18   DCHECK_EQ(rv, 0);
    19   rv = pthread_mutex_init(&os_lock_, &mta);
    20   DCHECK_EQ(rv, 0);
    21   rv = pthread_mutexattr_destroy(&mta);
    22   DCHECK_EQ(rv, 0);
    23 #else
    24   // In release, go with the default lock attributes.
    25   pthread_mutex_init(&os_lock_, NULL);
    26 #endif
    27 }
    29 LockImpl::~LockImpl() {
    30   int rv = pthread_mutex_destroy(&os_lock_);
    31   DCHECK_EQ(rv, 0);
    32 }
    34 bool LockImpl::Try() {
    35   int rv = pthread_mutex_trylock(&os_lock_);
    36   DCHECK(rv == 0 || rv == EBUSY);
    37   return rv == 0;
    38 }
    40 void LockImpl::Lock() {
    41   int rv = pthread_mutex_lock(&os_lock_);
    42   DCHECK_EQ(rv, 0);
    43 }
    45 void LockImpl::Unlock() {
    46   int rv = pthread_mutex_unlock(&os_lock_);
    47   DCHECK_EQ(rv, 0);
    48 }

mercurial