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

Side by Side Diff: mojo/edk/system/mutex.cc

Issue 1418043003: Remove mojo::system::Mutex's use of base::internal::LockImpl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 2 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 | « mojo/edk/system/mutex.h ('k') | mojo/edk/system/mutex_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/edk/system/mutex.h" 5 #include "mojo/edk/system/mutex.h"
6 6
7 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) 7 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
8 #include <errno.h>
9 #include <string.h>
8 10
9 #include "base/logging.h" 11 #include "base/logging.h"
10 12
11 namespace mojo { 13 namespace mojo {
12 namespace system { 14 namespace system {
13 15
14 Mutex::Mutex() : lock_() { 16 Mutex::Mutex() {
17 pthread_mutexattr_t attr;
18 int error = pthread_mutexattr_init(&attr);
19 DCHECK(!error) << "pthread_mutexattr_init: " << strerror(error);
20 error = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
21 DCHECK(!error) << "pthread_mutexattr_settype: " << strerror(error);
22 error = pthread_mutex_init(&impl_, &attr);
23 DCHECK(!error) << "pthread_mutex_init: " << strerror(error);
24 error = pthread_mutexattr_destroy(&attr);
25 DCHECK(!error) << "pthread_mutexattr_destroy: " << strerror(error);
15 } 26 }
16 27
17 Mutex::~Mutex() { 28 Mutex::~Mutex() {
18 DCHECK(owning_thread_ref_.is_null()); 29 int error = pthread_mutex_destroy(&impl_);
30 DCHECK(!error) << "pthread_mutex_destroy: " << strerror(error);
19 } 31 }
20 32
21 void Mutex::AssertHeld() const { 33 void Mutex::Lock() MOJO_EXCLUSIVE_LOCK_FUNCTION() {
22 DCHECK(owning_thread_ref_ == base::PlatformThread::CurrentRef()); 34 int error = pthread_mutex_lock(&impl_);
35 DCHECK(!error) << "pthread_mutex_lock: " << strerror(error);
23 } 36 }
24 37
25 void Mutex::CheckHeldAndUnmark() { 38 void Mutex::Unlock() MOJO_UNLOCK_FUNCTION() {
26 DCHECK(owning_thread_ref_ == base::PlatformThread::CurrentRef()); 39 int error = pthread_mutex_unlock(&impl_);
27 owning_thread_ref_ = base::PlatformThreadRef(); 40 DCHECK(!error) << "pthread_mutex_unlock: " << strerror(error);
28 } 41 }
29 42
30 void Mutex::CheckUnheldAndMark() { 43 bool Mutex::TryLock() MOJO_EXCLUSIVE_TRYLOCK_FUNCTION(true) {
31 DCHECK(owning_thread_ref_.is_null()); 44 int error = pthread_mutex_trylock(&impl_);
32 owning_thread_ref_ = base::PlatformThread::CurrentRef(); 45 DCHECK(!error || error == EBUSY) << "pthread_mutex_trylock: "
46 << strerror(error);
47 return !error;
48 }
49
50 void Mutex::AssertHeld() MOJO_ASSERT_EXCLUSIVE_LOCK() {
51 int error = pthread_mutex_lock(&impl_);
52 DCHECK_EQ(error, EDEADLK) << ". pthread_mutex_lock: " << strerror(error);
33 } 53 }
34 54
35 } // namespace system 55 } // namespace system
36 } // namespace mojo 56 } // namespace mojo
37 57
38 #endif // !NDEBUG || DCHECK_ALWAYS_ON 58 #endif // !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
OLDNEW
« no previous file with comments | « mojo/edk/system/mutex.h ('k') | mojo/edk/system/mutex_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698