1 // Copyright 2014 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 "mojo/public/utility/mutex.h"
12 // Release builds have inlined (non-error-checking) definitions in the header.
15 pthread_mutexattr_t mutexattr;
16 int rv = pthread_mutexattr_init(&mutexattr);
18 rv = pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_ERRORCHECK);
20 rv = pthread_mutex_init(&mutex_, &mutexattr);
22 rv = pthread_mutexattr_destroy(&mutexattr);
27 int rv = pthread_mutex_destroy(&mutex_);
32 int rv = pthread_mutex_lock(&mutex_);
36 void Mutex::Unlock() {
37 int rv = pthread_mutex_unlock(&mutex_);
41 bool Mutex::TryLock() {
42 int rv = pthread_mutex_trylock(&mutex_);
43 assert(rv == 0 || rv == EBUSY);
47 void Mutex::AssertHeld() {
48 assert(pthread_mutex_lock(&mutex_) == EDEADLK);
50 #endif // !defined(NDEBUG)