| OLD | NEW |
| 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): Currently, this is a fork of Chromium's | 7 // TODO(vtl): Currently, this is a fork of Chromium's |
| 8 // base/synchronization/lock.h (with names changed and minor modifications; it | 8 // base/synchronization/lock.h (with names changed and minor modifications; it |
| 9 // still cheats and uses Chromium's lock_impl.*), but eventually we'll want our | 9 // still cheats and uses Chromium's lock_impl.*), but eventually we'll want our |
| 10 // own and, e.g., add support for non-exclusive (reader) locks. | 10 // own and, e.g., add support for non-exclusive (reader) locks. |
| 11 | 11 |
| 12 #ifndef MOJO_EDK_SYSTEM_MUTEX_H_ | 12 #ifndef MOJO_EDK_SYSTEM_MUTEX_H_ |
| 13 #define MOJO_EDK_SYSTEM_MUTEX_H_ | 13 #define MOJO_EDK_SYSTEM_MUTEX_H_ |
| 14 | 14 |
| 15 #include "base/synchronization/lock_impl.h" | 15 #include "base/synchronization/lock_impl.h" |
| 16 #include "base/threading/platform_thread.h" | 16 #include "base/threading/platform_thread.h" |
| 17 #include "mojo/edk/system/system_impl_export.h" | 17 #include "mojo/edk/system/system_impl_export.h" |
| 18 #include "mojo/edk/system/thread_annotations.h" | 18 #include "mojo/edk/system/thread_annotations.h" |
| 19 #include "mojo/public/cpp/system/macros.h" | 19 #include "mojo/public/cpp/system/macros.h" |
| 20 | 20 |
| 21 namespace mojo { | 21 namespace mojo { |
| 22 namespace system { | 22 namespace system { |
| 23 | 23 |
| 24 // Mutex ----------------------------------------------------------------------- | 24 // Mutex ----------------------------------------------------------------------- |
| 25 | 25 |
| 26 class MOJO_SYSTEM_IMPL_EXPORT MOJO_LOCKABLE Mutex { | 26 class MOJO_LOCKABLE MOJO_SYSTEM_IMPL_EXPORT Mutex { |
| 27 public: | 27 public: |
| 28 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) | 28 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) |
| 29 Mutex() : lock_() {} | 29 Mutex() : lock_() {} |
| 30 ~Mutex() {} | 30 ~Mutex() {} |
| 31 | 31 |
| 32 void Lock() MOJO_EXCLUSIVE_LOCK_FUNCTION() { lock_.Lock(); } | 32 void Lock() MOJO_EXCLUSIVE_LOCK_FUNCTION() { lock_.Lock(); } |
| 33 void Unlock() MOJO_UNLOCK_FUNCTION() { lock_.Unlock(); } | 33 void Unlock() MOJO_UNLOCK_FUNCTION() { lock_.Unlock(); } |
| 34 | 34 |
| 35 bool TryLock() MOJO_EXCLUSIVE_TRYLOCK_FUNCTION(true) { return lock_.Try(); } | 35 bool TryLock() MOJO_EXCLUSIVE_TRYLOCK_FUNCTION(true) { return lock_.Try(); } |
| 36 | 36 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 66 base::PlatformThreadRef owning_thread_ref_; | 66 base::PlatformThreadRef owning_thread_ref_; |
| 67 #endif // !NDEBUG || DCHECK_ALWAYS_ON | 67 #endif // !NDEBUG || DCHECK_ALWAYS_ON |
| 68 | 68 |
| 69 base::internal::LockImpl lock_; | 69 base::internal::LockImpl lock_; |
| 70 | 70 |
| 71 MOJO_DISALLOW_COPY_AND_ASSIGN(Mutex); | 71 MOJO_DISALLOW_COPY_AND_ASSIGN(Mutex); |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 // MutexLocker ----------------------------------------------------------------- | 74 // MutexLocker ----------------------------------------------------------------- |
| 75 | 75 |
| 76 class MOJO_SYSTEM_IMPL_EXPORT MOJO_SCOPED_LOCKABLE MutexLocker { | 76 class MOJO_SCOPED_LOCKABLE MOJO_SYSTEM_IMPL_EXPORT MutexLocker { |
| 77 public: | 77 public: |
| 78 explicit MutexLocker(Mutex* mutex) MOJO_EXCLUSIVE_LOCK_FUNCTION(mutex) | 78 explicit MutexLocker(Mutex* mutex) MOJO_EXCLUSIVE_LOCK_FUNCTION(mutex) |
| 79 : mutex_(mutex) { | 79 : mutex_(mutex) { |
| 80 this->mutex_->Lock(); | 80 this->mutex_->Lock(); |
| 81 } | 81 } |
| 82 ~MutexLocker() MOJO_UNLOCK_FUNCTION() { this->mutex_->Unlock(); } | 82 ~MutexLocker() MOJO_UNLOCK_FUNCTION() { this->mutex_->Unlock(); } |
| 83 | 83 |
| 84 private: | 84 private: |
| 85 Mutex* const mutex_; | 85 Mutex* const mutex_; |
| 86 | 86 |
| 87 MOJO_DISALLOW_COPY_AND_ASSIGN(MutexLocker); | 87 MOJO_DISALLOW_COPY_AND_ASSIGN(MutexLocker); |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 } // namespace system | 90 } // namespace system |
| 91 } // namespace mojo | 91 } // namespace mojo |
| 92 | 92 |
| 93 #endif // MOJO_EDK_SYSTEM_MUTEX_H_ | 93 #endif // MOJO_EDK_SYSTEM_MUTEX_H_ |
| OLD | NEW |