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

Side by Side Diff: mojo/edk/util/mutex.h

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/util/logging_internal.cc ('k') | mojo/edk/util/mutex.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 2015 The Chromium Authors. All rights reserved. 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 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 // A mutex class, with support for thread annotations. 5 // A mutex class, with support for thread annotations.
6 // 6 //
7 // TODO(vtl): Add support for non-exclusive (reader) locks. 7 // TODO(vtl): Add support for non-exclusive (reader) locks.
8 8
9 #ifndef MOJO_EDK_SYSTEM_MUTEX_H_ 9 #ifndef MOJO_EDK_UTIL_MUTEX_H_
10 #define MOJO_EDK_SYSTEM_MUTEX_H_ 10 #define MOJO_EDK_UTIL_MUTEX_H_
11 11
12 #include <pthread.h> 12 #include <pthread.h>
13 13
14 #include "mojo/edk/system/thread_annotations.h" 14 #include "mojo/edk/util/thread_annotations.h"
15 #include "mojo/public/cpp/system/macros.h" 15 #include "mojo/public/cpp/system/macros.h"
16 16
17 namespace mojo { 17 namespace mojo {
18 namespace system { 18 namespace util {
19
20 // So |Mutex| can friend it.
21 class CondVar;
22 19
23 // Mutex ----------------------------------------------------------------------- 20 // Mutex -----------------------------------------------------------------------
24 21
22 class CondVar;
23
25 class MOJO_LOCKABLE Mutex { 24 class MOJO_LOCKABLE Mutex {
26 public: 25 public:
27 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) 26 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
28 Mutex() { pthread_mutex_init(&impl_, nullptr); } 27 Mutex() { pthread_mutex_init(&impl_, nullptr); }
29 ~Mutex() { pthread_mutex_destroy(&impl_); } 28 ~Mutex() { pthread_mutex_destroy(&impl_); }
30 29
31 // Takes an exclusive lock. 30 // Takes an exclusive lock.
32 void Lock() MOJO_EXCLUSIVE_LOCK_FUNCTION() { pthread_mutex_lock(&impl_); } 31 void Lock() MOJO_EXCLUSIVE_LOCK_FUNCTION() { pthread_mutex_lock(&impl_); }
33 32
34 // Releases a lock. 33 // Releases a lock.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 this->mutex_->Lock(); 70 this->mutex_->Lock();
72 } 71 }
73 ~MutexLocker() MOJO_UNLOCK_FUNCTION() { this->mutex_->Unlock(); } 72 ~MutexLocker() MOJO_UNLOCK_FUNCTION() { this->mutex_->Unlock(); }
74 73
75 private: 74 private:
76 Mutex* const mutex_; 75 Mutex* const mutex_;
77 76
78 MOJO_DISALLOW_COPY_AND_ASSIGN(MutexLocker); 77 MOJO_DISALLOW_COPY_AND_ASSIGN(MutexLocker);
79 }; 78 };
80 79
81 } // namespace system 80 } // namespace util
82 } // namespace mojo 81 } // namespace mojo
83 82
84 #endif // MOJO_EDK_SYSTEM_MUTEX_H_ 83 #endif // MOJO_EDK_UTIL_MUTEX_H_
OLDNEW
« no previous file with comments | « mojo/edk/util/logging_internal.cc ('k') | mojo/edk/util/mutex.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698