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

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

Issue 1426343002: EDK: Move mutex.*, cond_var.*, and thread_annotations.h to //mojo/edk/util. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: oops Created 5 years, 1 month 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
(Empty)
1 // Copyright 2015 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.
4
5 #include "mojo/edk/system/mutex.h"
6
7 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
8 #include <errno.h>
9 #include <string.h>
10
11 #include "base/logging.h"
12
13 namespace mojo {
14 namespace system {
15
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);
26 }
27
28 Mutex::~Mutex() {
29 int error = pthread_mutex_destroy(&impl_);
30 DCHECK(!error) << "pthread_mutex_destroy: " << strerror(error);
31 }
32
33 void Mutex::Lock() MOJO_EXCLUSIVE_LOCK_FUNCTION() {
34 int error = pthread_mutex_lock(&impl_);
35 DCHECK(!error) << "pthread_mutex_lock: " << strerror(error);
36 }
37
38 void Mutex::Unlock() MOJO_UNLOCK_FUNCTION() {
39 int error = pthread_mutex_unlock(&impl_);
40 DCHECK(!error) << "pthread_mutex_unlock: " << strerror(error);
41 }
42
43 bool Mutex::TryLock() MOJO_EXCLUSIVE_TRYLOCK_FUNCTION(true) {
44 int error = pthread_mutex_trylock(&impl_);
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);
53 }
54
55 } // namespace system
56 } // namespace mojo
57
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