Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_BASE_MUTEX_H_ |
| 18 | #define ART_RUNTIME_BASE_MUTEX_H_ |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 19 | |
| 20 | #include <pthread.h> |
Brian Carlstrom | cd74c4b | 2012-01-23 13:21:00 -0800 | [diff] [blame] | 21 | #include <stdint.h> |
Hans Boehm | 0882af2 | 2017-08-31 15:21:57 -0700 | [diff] [blame] | 22 | #include <unistd.h> // for pid_t |
Elliott Hughes | ffb465f | 2012-03-01 18:46:05 -0800 | [diff] [blame] | 23 | |
| 24 | #include <iosfwd> |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 25 | #include <string> |
| 26 | |
Andreas Gampe | 5794381 | 2017-12-06 21:39:13 -0800 | [diff] [blame] | 27 | #include <android-base/logging.h> |
| 28 | |
Andreas Gampe | 39b378c | 2017-12-07 15:44:13 -0800 | [diff] [blame] | 29 | #include "base/aborting.h" |
David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 30 | #include "base/atomic.h" |
Andreas Gampe | 5a0430d | 2019-01-04 14:33:57 -0800 | [diff] [blame] | 31 | #include "runtime_globals.h" |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 32 | #include "base/macros.h" |
Andreas Gampe | 7cc45fd | 2018-11-21 16:03:08 -0800 | [diff] [blame] | 33 | #include "locks.h" |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 34 | |
Daniel Colascione | b4dfca5 | 2018-04-15 11:15:14 -0700 | [diff] [blame] | 35 | #if defined(__linux__) |
Chris Dearman | c014178 | 2013-11-14 17:29:21 -0800 | [diff] [blame] | 36 | #define ART_USE_FUTEXES 1 |
Daniel Colascione | b4dfca5 | 2018-04-15 11:15:14 -0700 | [diff] [blame] | 37 | #else |
| 38 | #define ART_USE_FUTEXES 0 |
Ian Rogers | ab47016 | 2012-09-29 23:06:53 -0700 | [diff] [blame] | 39 | #endif |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 40 | |
Ian Rogers | 66aee5c | 2012-08-15 17:17:47 -0700 | [diff] [blame] | 41 | // Currently Darwin doesn't support locks with timeouts. |
| 42 | #if !defined(__APPLE__) |
| 43 | #define HAVE_TIMED_RWLOCK 1 |
| 44 | #else |
| 45 | #define HAVE_TIMED_RWLOCK 0 |
| 46 | #endif |
| 47 | |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 48 | namespace art { |
| 49 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 50 | class SHARED_LOCKABLE ReaderWriterMutex; |
| 51 | class SHARED_LOCKABLE MutatorMutex; |
Ian Rogers | 56edc43 | 2013-01-18 16:51:51 -0800 | [diff] [blame] | 52 | class ScopedContentionRecorder; |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 53 | class Thread; |
Andreas Gampe | 7cc45fd | 2018-11-21 16:03:08 -0800 | [diff] [blame] | 54 | class LOCKABLE Mutex; |
Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 55 | |
Andreas Gampe | 5db8b7b | 2018-05-08 16:10:59 -0700 | [diff] [blame] | 56 | constexpr bool kDebugLocking = kIsDebugBuild; |
Ian Rogers | 25fd14b | 2012-09-05 10:56:38 -0700 | [diff] [blame] | 57 | |
Hiroshi Yamauchi | 1afde13 | 2013-08-06 17:09:30 -0700 | [diff] [blame] | 58 | // Record Log contention information, dumpable via SIGQUIT. |
| 59 | #ifdef ART_USE_FUTEXES |
Jeff Hao | 08f2e7b | 2013-09-09 16:44:02 -0700 | [diff] [blame] | 60 | // To enable lock contention logging, set this to true. |
Andreas Gampe | 5db8b7b | 2018-05-08 16:10:59 -0700 | [diff] [blame] | 61 | constexpr bool kLogLockContentions = false; |
Hiroshi Yamauchi | 1afde13 | 2013-08-06 17:09:30 -0700 | [diff] [blame] | 62 | #else |
| 63 | // Keep this false as lock contention logging is supported only with |
| 64 | // futex. |
Andreas Gampe | 5db8b7b | 2018-05-08 16:10:59 -0700 | [diff] [blame] | 65 | constexpr bool kLogLockContentions = false; |
Hiroshi Yamauchi | 1afde13 | 2013-08-06 17:09:30 -0700 | [diff] [blame] | 66 | #endif |
Andreas Gampe | 5db8b7b | 2018-05-08 16:10:59 -0700 | [diff] [blame] | 67 | constexpr size_t kContentionLogSize = 4; |
| 68 | constexpr size_t kContentionLogDataSize = kLogLockContentions ? 1 : 0; |
| 69 | constexpr size_t kAllMutexDataSize = kLogLockContentions ? 1 : 0; |
Hiroshi Yamauchi | 1afde13 | 2013-08-06 17:09:30 -0700 | [diff] [blame] | 70 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 71 | // Base class for all Mutex implementations |
| 72 | class BaseMutex { |
| 73 | public: |
Ian Rogers | bab7496 | 2013-04-19 10:04:10 -0700 | [diff] [blame] | 74 | const char* GetName() const { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 75 | return name_; |
| 76 | } |
| 77 | |
| 78 | virtual bool IsMutex() const { return false; } |
| 79 | virtual bool IsReaderWriterMutex() const { return false; } |
Yu Li | eac4424 | 2015-06-29 10:50:03 +0800 | [diff] [blame] | 80 | virtual bool IsMutatorMutex() const { return false; } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 81 | |
Ian Rogers | 56edc43 | 2013-01-18 16:51:51 -0800 | [diff] [blame] | 82 | virtual void Dump(std::ostream& os) const = 0; |
| 83 | |
| 84 | static void DumpAll(std::ostream& os); |
| 85 | |
Hiroshi Yamauchi | a222404 | 2017-02-08 16:35:45 -0800 | [diff] [blame] | 86 | bool ShouldRespondToEmptyCheckpointRequest() const { |
| 87 | return should_respond_to_empty_checkpoint_request_; |
| 88 | } |
| 89 | |
| 90 | void SetShouldRespondToEmptyCheckpointRequest(bool value) { |
| 91 | should_respond_to_empty_checkpoint_request_ = value; |
| 92 | } |
| 93 | |
| 94 | virtual void WakeupToRespondToEmptyCheckpoint() = 0; |
| 95 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 96 | protected: |
| 97 | friend class ConditionVariable; |
| 98 | |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 99 | BaseMutex(const char* name, LockLevel level); |
Ian Rogers | 56edc43 | 2013-01-18 16:51:51 -0800 | [diff] [blame] | 100 | virtual ~BaseMutex(); |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 101 | void RegisterAsLocked(Thread* self); |
| 102 | void RegisterAsUnlocked(Thread* self); |
| 103 | void CheckSafeToWait(Thread* self); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 104 | |
Ian Rogers | 56edc43 | 2013-01-18 16:51:51 -0800 | [diff] [blame] | 105 | friend class ScopedContentionRecorder; |
| 106 | |
Hiroshi Yamauchi | 1afde13 | 2013-08-06 17:09:30 -0700 | [diff] [blame] | 107 | void RecordContention(uint64_t blocked_tid, uint64_t owner_tid, uint64_t nano_time_blocked); |
Ian Rogers | 56edc43 | 2013-01-18 16:51:51 -0800 | [diff] [blame] | 108 | void DumpContention(std::ostream& os) const; |
| 109 | |
Ian Rogers | bab7496 | 2013-04-19 10:04:10 -0700 | [diff] [blame] | 110 | const char* const name_; |
Hiroshi Yamauchi | 1afde13 | 2013-08-06 17:09:30 -0700 | [diff] [blame] | 111 | |
Ian Rogers | 56edc43 | 2013-01-18 16:51:51 -0800 | [diff] [blame] | 112 | // A log entry that records contention but makes no guarantee that either tid will be held live. |
| 113 | struct ContentionLogEntry { |
| 114 | ContentionLogEntry() : blocked_tid(0), owner_tid(0) {} |
| 115 | uint64_t blocked_tid; |
| 116 | uint64_t owner_tid; |
| 117 | AtomicInteger count; |
| 118 | }; |
Hiroshi Yamauchi | 1afde13 | 2013-08-06 17:09:30 -0700 | [diff] [blame] | 119 | struct ContentionLogData { |
| 120 | ContentionLogEntry contention_log[kContentionLogSize]; |
| 121 | // The next entry in the contention log to be updated. Value ranges from 0 to |
| 122 | // kContentionLogSize - 1. |
| 123 | AtomicInteger cur_content_log_entry; |
| 124 | // Number of times the Mutex has been contended. |
| 125 | AtomicInteger contention_count; |
| 126 | // Sum of time waited by all contenders in ns. |
Ian Rogers | 37f3c96 | 2014-07-17 11:25:30 -0700 | [diff] [blame] | 127 | Atomic<uint64_t> wait_time; |
Hiroshi Yamauchi | 1afde13 | 2013-08-06 17:09:30 -0700 | [diff] [blame] | 128 | void AddToWaitTime(uint64_t value); |
| 129 | ContentionLogData() : wait_time(0) {} |
| 130 | }; |
Ian Rogers | 3e5cf30 | 2014-05-20 16:40:37 -0700 | [diff] [blame] | 131 | ContentionLogData contention_log_data_[kContentionLogDataSize]; |
Hiroshi Yamauchi | 1afde13 | 2013-08-06 17:09:30 -0700 | [diff] [blame] | 132 | |
Andreas Gampe | 5db8b7b | 2018-05-08 16:10:59 -0700 | [diff] [blame] | 133 | const LockLevel level_; // Support for lock hierarchy. |
| 134 | bool should_respond_to_empty_checkpoint_request_; |
| 135 | |
Hiroshi Yamauchi | 1afde13 | 2013-08-06 17:09:30 -0700 | [diff] [blame] | 136 | public: |
| 137 | bool HasEverContended() const { |
| 138 | if (kLogLockContentions) { |
Orion Hodson | 88591fe | 2018-03-06 13:35:43 +0000 | [diff] [blame] | 139 | return contention_log_data_->contention_count.load(std::memory_order_seq_cst) > 0; |
Hiroshi Yamauchi | 1afde13 | 2013-08-06 17:09:30 -0700 | [diff] [blame] | 140 | } |
| 141 | return false; |
| 142 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | // A Mutex is used to achieve mutual exclusion between threads. A Mutex can be used to gain |
| 146 | // exclusive access to what it guards. A Mutex can be in one of two states: |
| 147 | // - Free - not owned by any thread, |
| 148 | // - Exclusive - owned by a single thread. |
| 149 | // |
| 150 | // The effect of locking and unlocking operations on the state is: |
| 151 | // State | ExclusiveLock | ExclusiveUnlock |
| 152 | // ------------------------------------------- |
| 153 | // Free | Exclusive | error |
| 154 | // Exclusive | Block* | Free |
| 155 | // * Mutex is not reentrant and so an attempt to ExclusiveLock on the same thread will result in |
| 156 | // an error. Being non-reentrant simplifies Waiting on ConditionVariables. |
Ian Rogers | 01ae580 | 2012-09-28 16:14:01 -0700 | [diff] [blame] | 157 | std::ostream& operator<<(std::ostream& os, const Mutex& mu); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 158 | class LOCKABLE Mutex : public BaseMutex { |
| 159 | public: |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 160 | explicit Mutex(const char* name, LockLevel level = kDefaultMutexLevel, bool recursive = false); |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 161 | ~Mutex(); |
| 162 | |
Yi Kong | 3940254 | 2019-03-24 02:47:16 -0700 | [diff] [blame] | 163 | bool IsMutex() const override { return true; } |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 164 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 165 | // Block until mutex is free then acquire exclusive access. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 166 | void ExclusiveLock(Thread* self) ACQUIRE(); |
| 167 | void Lock(Thread* self) ACQUIRE() { ExclusiveLock(self); } |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 168 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 169 | // Returns true if acquires exclusive access, false otherwise. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 170 | bool ExclusiveTryLock(Thread* self) TRY_ACQUIRE(true); |
| 171 | bool TryLock(Thread* self) TRY_ACQUIRE(true) { return ExclusiveTryLock(self); } |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 172 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 173 | // Release exclusive access. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 174 | void ExclusiveUnlock(Thread* self) RELEASE(); |
| 175 | void Unlock(Thread* self) RELEASE() { ExclusiveUnlock(self); } |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 176 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 177 | // Is the current thread the exclusive holder of the Mutex. |
Andreas Gampe | b486a98 | 2017-06-01 13:45:54 -0700 | [diff] [blame] | 178 | ALWAYS_INLINE bool IsExclusiveHeld(const Thread* self) const; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 179 | |
| 180 | // Assert that the Mutex is exclusively held by the current thread. |
Andreas Gampe | b486a98 | 2017-06-01 13:45:54 -0700 | [diff] [blame] | 181 | ALWAYS_INLINE void AssertExclusiveHeld(const Thread* self) const ASSERT_CAPABILITY(this); |
| 182 | ALWAYS_INLINE void AssertHeld(const Thread* self) const ASSERT_CAPABILITY(this); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 183 | |
| 184 | // Assert that the Mutex is not held by the current thread. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 185 | void AssertNotHeldExclusive(const Thread* self) ASSERT_CAPABILITY(!*this) { |
Nicolas Geoffray | db97871 | 2014-12-09 13:33:38 +0000 | [diff] [blame] | 186 | if (kDebugLocking && (gAborting == 0)) { |
Ian Rogers | 01ae580 | 2012-09-28 16:14:01 -0700 | [diff] [blame] | 187 | CHECK(!IsExclusiveHeld(self)) << *this; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 188 | } |
| 189 | } |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 190 | void AssertNotHeld(const Thread* self) ASSERT_CAPABILITY(!*this) { |
| 191 | AssertNotHeldExclusive(self); |
| 192 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 193 | |
Ian Rogers | c719069 | 2014-07-08 23:50:26 -0700 | [diff] [blame] | 194 | // Id associated with exclusive owner. No memory ordering semantics if called from a thread other |
| 195 | // than the owner. |
Hans Boehm | 0882af2 | 2017-08-31 15:21:57 -0700 | [diff] [blame] | 196 | pid_t GetExclusiveOwnerTid() const; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 197 | |
| 198 | // Returns how many times this Mutex has been locked, it is better to use AssertHeld/NotHeld. |
| 199 | unsigned int GetDepth() const { |
| 200 | return recursion_count_; |
| 201 | } |
Elliott Hughes | accd83d | 2011-10-17 14:25:58 -0700 | [diff] [blame] | 202 | |
Yi Kong | 3940254 | 2019-03-24 02:47:16 -0700 | [diff] [blame] | 203 | void Dump(std::ostream& os) const override; |
Ian Rogers | 01ae580 | 2012-09-28 16:14:01 -0700 | [diff] [blame] | 204 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 205 | // For negative capabilities in clang annotations. |
| 206 | const Mutex& operator!() const { return *this; } |
| 207 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 208 | void WakeupToRespondToEmptyCheckpoint() override; |
Hiroshi Yamauchi | a222404 | 2017-02-08 16:35:45 -0800 | [diff] [blame] | 209 | |
Elliott Hughes | accd83d | 2011-10-17 14:25:58 -0700 | [diff] [blame] | 210 | private: |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 211 | #if ART_USE_FUTEXES |
| 212 | // 0 is unheld, 1 is held. |
Ian Rogers | c719069 | 2014-07-08 23:50:26 -0700 | [diff] [blame] | 213 | AtomicInteger state_; |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 214 | // Exclusive owner. |
Hans Boehm | 0882af2 | 2017-08-31 15:21:57 -0700 | [diff] [blame] | 215 | Atomic<pid_t> exclusive_owner_; |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 216 | // Number of waiting contenders. |
Ian Rogers | b122a4b | 2013-11-19 18:00:50 -0800 | [diff] [blame] | 217 | AtomicInteger num_contenders_; |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 218 | #else |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 219 | pthread_mutex_t mutex_; |
Hans Boehm | 0882af2 | 2017-08-31 15:21:57 -0700 | [diff] [blame] | 220 | Atomic<pid_t> exclusive_owner_; // Guarded by mutex_. Asynchronous reads are OK. |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 221 | #endif |
Andreas Gampe | 5db8b7b | 2018-05-08 16:10:59 -0700 | [diff] [blame] | 222 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 223 | unsigned int recursion_count_; |
Andreas Gampe | 5db8b7b | 2018-05-08 16:10:59 -0700 | [diff] [blame] | 224 | const bool recursive_; // Can the lock be recursively held? |
| 225 | |
Elliott Hughes | f149843 | 2012-03-28 19:34:27 -0700 | [diff] [blame] | 226 | friend class ConditionVariable; |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 227 | DISALLOW_COPY_AND_ASSIGN(Mutex); |
| 228 | }; |
| 229 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 230 | // A ReaderWriterMutex is used to achieve mutual exclusion between threads, similar to a Mutex. |
| 231 | // Unlike a Mutex a ReaderWriterMutex can be used to gain exclusive (writer) or shared (reader) |
| 232 | // access to what it guards. A flaw in relation to a Mutex is that it cannot be used with a |
| 233 | // condition variable. A ReaderWriterMutex can be in one of three states: |
| 234 | // - Free - not owned by any thread, |
| 235 | // - Exclusive - owned by a single thread, |
| 236 | // - Shared(n) - shared amongst n threads. |
| 237 | // |
| 238 | // The effect of locking and unlocking operations on the state is: |
| 239 | // |
| 240 | // State | ExclusiveLock | ExclusiveUnlock | SharedLock | SharedUnlock |
| 241 | // ---------------------------------------------------------------------------- |
| 242 | // Free | Exclusive | error | SharedLock(1) | error |
| 243 | // Exclusive | Block | Free | Block | error |
| 244 | // Shared(n) | Block | error | SharedLock(n+1)* | Shared(n-1) or Free |
| 245 | // * for large values of n the SharedLock may block. |
Ian Rogers | 01ae580 | 2012-09-28 16:14:01 -0700 | [diff] [blame] | 246 | std::ostream& operator<<(std::ostream& os, const ReaderWriterMutex& mu); |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 247 | class SHARED_LOCKABLE ReaderWriterMutex : public BaseMutex { |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 248 | public: |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 249 | explicit ReaderWriterMutex(const char* name, LockLevel level = kDefaultMutexLevel); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 250 | ~ReaderWriterMutex(); |
| 251 | |
Yi Kong | 3940254 | 2019-03-24 02:47:16 -0700 | [diff] [blame] | 252 | bool IsReaderWriterMutex() const override { return true; } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 253 | |
| 254 | // Block until ReaderWriterMutex is free then acquire exclusive access. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 255 | void ExclusiveLock(Thread* self) ACQUIRE(); |
| 256 | void WriterLock(Thread* self) ACQUIRE() { ExclusiveLock(self); } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 257 | |
| 258 | // Release exclusive access. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 259 | void ExclusiveUnlock(Thread* self) RELEASE(); |
| 260 | void WriterUnlock(Thread* self) RELEASE() { ExclusiveUnlock(self); } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 261 | |
| 262 | // Block until ReaderWriterMutex is free and acquire exclusive access. Returns true on success |
| 263 | // or false if timeout is reached. |
Ian Rogers | 66aee5c | 2012-08-15 17:17:47 -0700 | [diff] [blame] | 264 | #if HAVE_TIMED_RWLOCK |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 265 | bool ExclusiveLockWithTimeout(Thread* self, int64_t ms, int32_t ns) |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 266 | EXCLUSIVE_TRYLOCK_FUNCTION(true); |
Ian Rogers | 66aee5c | 2012-08-15 17:17:47 -0700 | [diff] [blame] | 267 | #endif |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 268 | |
| 269 | // Block until ReaderWriterMutex is shared or free then acquire a share on the access. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 270 | void SharedLock(Thread* self) ACQUIRE_SHARED() ALWAYS_INLINE; |
| 271 | void ReaderLock(Thread* self) ACQUIRE_SHARED() { SharedLock(self); } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 272 | |
| 273 | // Try to acquire share of ReaderWriterMutex. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 274 | bool SharedTryLock(Thread* self) SHARED_TRYLOCK_FUNCTION(true); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 275 | |
| 276 | // Release a share of the access. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 277 | void SharedUnlock(Thread* self) RELEASE_SHARED() ALWAYS_INLINE; |
| 278 | void ReaderUnlock(Thread* self) RELEASE_SHARED() { SharedUnlock(self); } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 279 | |
| 280 | // Is the current thread the exclusive holder of the ReaderWriterMutex. |
Andreas Gampe | b486a98 | 2017-06-01 13:45:54 -0700 | [diff] [blame] | 281 | ALWAYS_INLINE bool IsExclusiveHeld(const Thread* self) const; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 282 | |
| 283 | // Assert the current thread has exclusive access to the ReaderWriterMutex. |
Andreas Gampe | b486a98 | 2017-06-01 13:45:54 -0700 | [diff] [blame] | 284 | ALWAYS_INLINE void AssertExclusiveHeld(const Thread* self) const ASSERT_CAPABILITY(this); |
| 285 | ALWAYS_INLINE void AssertWriterHeld(const Thread* self) const ASSERT_CAPABILITY(this); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 286 | |
| 287 | // Assert the current thread doesn't have exclusive access to the ReaderWriterMutex. |
Mathieu Chartier | 90ef3db | 2015-08-04 15:19:41 -0700 | [diff] [blame] | 288 | void AssertNotExclusiveHeld(const Thread* self) ASSERT_CAPABILITY(!this) { |
Nicolas Geoffray | db97871 | 2014-12-09 13:33:38 +0000 | [diff] [blame] | 289 | if (kDebugLocking && (gAborting == 0)) { |
Ian Rogers | e3359f7 | 2013-06-11 15:14:11 -0700 | [diff] [blame] | 290 | CHECK(!IsExclusiveHeld(self)) << *this; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 291 | } |
| 292 | } |
Mathieu Chartier | 90ef3db | 2015-08-04 15:19:41 -0700 | [diff] [blame] | 293 | void AssertNotWriterHeld(const Thread* self) ASSERT_CAPABILITY(!this) { |
| 294 | AssertNotExclusiveHeld(self); |
| 295 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 296 | |
| 297 | // Is the current thread a shared holder of the ReaderWriterMutex. |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 298 | bool IsSharedHeld(const Thread* self) const; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 299 | |
| 300 | // Assert the current thread has shared access to the ReaderWriterMutex. |
Mathieu Chartier | 3768ade | 2017-05-02 14:04:39 -0700 | [diff] [blame] | 301 | ALWAYS_INLINE void AssertSharedHeld(const Thread* self) ASSERT_SHARED_CAPABILITY(this) { |
Nicolas Geoffray | db97871 | 2014-12-09 13:33:38 +0000 | [diff] [blame] | 302 | if (kDebugLocking && (gAborting == 0)) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 303 | // TODO: we can only assert this well when self != null. |
| 304 | CHECK(IsSharedHeld(self) || self == nullptr) << *this; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 305 | } |
| 306 | } |
Mathieu Chartier | 3768ade | 2017-05-02 14:04:39 -0700 | [diff] [blame] | 307 | ALWAYS_INLINE void AssertReaderHeld(const Thread* self) ASSERT_SHARED_CAPABILITY(this) { |
Mathieu Chartier | 90ef3db | 2015-08-04 15:19:41 -0700 | [diff] [blame] | 308 | AssertSharedHeld(self); |
| 309 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 310 | |
| 311 | // Assert the current thread doesn't hold this ReaderWriterMutex either in shared or exclusive |
| 312 | // mode. |
Mathieu Chartier | 3768ade | 2017-05-02 14:04:39 -0700 | [diff] [blame] | 313 | ALWAYS_INLINE void AssertNotHeld(const Thread* self) ASSERT_SHARED_CAPABILITY(!this) { |
Nicolas Geoffray | db97871 | 2014-12-09 13:33:38 +0000 | [diff] [blame] | 314 | if (kDebugLocking && (gAborting == 0)) { |
Ian Rogers | 01ae580 | 2012-09-28 16:14:01 -0700 | [diff] [blame] | 315 | CHECK(!IsSharedHeld(self)) << *this; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 316 | } |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Ian Rogers | c719069 | 2014-07-08 23:50:26 -0700 | [diff] [blame] | 319 | // Id associated with exclusive owner. No memory ordering semantics if called from a thread other |
Hans Boehm | 0882af2 | 2017-08-31 15:21:57 -0700 | [diff] [blame] | 320 | // than the owner. Returns 0 if the lock is not held. Returns either 0 or -1 if it is held by |
| 321 | // one or more readers. |
| 322 | pid_t GetExclusiveOwnerTid() const; |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 323 | |
Yi Kong | 3940254 | 2019-03-24 02:47:16 -0700 | [diff] [blame] | 324 | void Dump(std::ostream& os) const override; |
Ian Rogers | 01ae580 | 2012-09-28 16:14:01 -0700 | [diff] [blame] | 325 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 326 | // For negative capabilities in clang annotations. |
| 327 | const ReaderWriterMutex& operator!() const { return *this; } |
| 328 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 329 | void WakeupToRespondToEmptyCheckpoint() override; |
Hiroshi Yamauchi | a222404 | 2017-02-08 16:35:45 -0800 | [diff] [blame] | 330 | |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 331 | private: |
Ian Rogers | 51d212e | 2014-10-23 17:48:20 -0700 | [diff] [blame] | 332 | #if ART_USE_FUTEXES |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 333 | // Out-of-inline path for handling contention for a SharedLock. |
| 334 | void HandleSharedLockContention(Thread* self, int32_t cur_state); |
| 335 | |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 336 | // -1 implies held exclusive, +ve shared held by state_ many owners. |
Ian Rogers | c719069 | 2014-07-08 23:50:26 -0700 | [diff] [blame] | 337 | AtomicInteger state_; |
| 338 | // Exclusive owner. Modification guarded by this mutex. |
Hans Boehm | 0882af2 | 2017-08-31 15:21:57 -0700 | [diff] [blame] | 339 | Atomic<pid_t> exclusive_owner_; |
Ian Rogers | c719069 | 2014-07-08 23:50:26 -0700 | [diff] [blame] | 340 | // Number of contenders waiting for a reader share. |
| 341 | AtomicInteger num_pending_readers_; |
| 342 | // Number of contenders waiting to be the writer. |
Ian Rogers | b122a4b | 2013-11-19 18:00:50 -0800 | [diff] [blame] | 343 | AtomicInteger num_pending_writers_; |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 344 | #else |
| 345 | pthread_rwlock_t rwlock_; |
Hans Boehm | 0882af2 | 2017-08-31 15:21:57 -0700 | [diff] [blame] | 346 | Atomic<pid_t> exclusive_owner_; // Writes guarded by rwlock_. Asynchronous reads are OK. |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 347 | #endif |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 348 | DISALLOW_COPY_AND_ASSIGN(ReaderWriterMutex); |
| 349 | }; |
| 350 | |
Yu Li | eac4424 | 2015-06-29 10:50:03 +0800 | [diff] [blame] | 351 | // MutatorMutex is a special kind of ReaderWriterMutex created specifically for the |
| 352 | // Locks::mutator_lock_ mutex. The behaviour is identical to the ReaderWriterMutex except that |
| 353 | // thread state changes also play a part in lock ownership. The mutator_lock_ will not be truly |
| 354 | // held by any mutator threads. However, a thread in the kRunnable state is considered to have |
| 355 | // shared ownership of the mutator lock and therefore transitions in and out of the kRunnable |
| 356 | // state have associated implications on lock ownership. Extra methods to handle the state |
| 357 | // transitions have been added to the interface but are only accessible to the methods dealing |
| 358 | // with state transitions. The thread state and flags attributes are used to ensure thread state |
| 359 | // transitions are consistent with the permitted behaviour of the mutex. |
| 360 | // |
| 361 | // *) The most important consequence of this behaviour is that all threads must be in one of the |
| 362 | // suspended states before exclusive ownership of the mutator mutex is sought. |
| 363 | // |
| 364 | std::ostream& operator<<(std::ostream& os, const MutatorMutex& mu); |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 365 | class SHARED_LOCKABLE MutatorMutex : public ReaderWriterMutex { |
Yu Li | eac4424 | 2015-06-29 10:50:03 +0800 | [diff] [blame] | 366 | public: |
| 367 | explicit MutatorMutex(const char* name, LockLevel level = kDefaultMutexLevel) |
| 368 | : ReaderWriterMutex(name, level) {} |
| 369 | ~MutatorMutex() {} |
| 370 | |
| 371 | virtual bool IsMutatorMutex() const { return true; } |
| 372 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 373 | // For negative capabilities in clang annotations. |
| 374 | const MutatorMutex& operator!() const { return *this; } |
| 375 | |
Yu Li | eac4424 | 2015-06-29 10:50:03 +0800 | [diff] [blame] | 376 | private: |
| 377 | friend class Thread; |
| 378 | void TransitionFromRunnableToSuspended(Thread* self) UNLOCK_FUNCTION() ALWAYS_INLINE; |
| 379 | void TransitionFromSuspendedToRunnable(Thread* self) SHARED_LOCK_FUNCTION() ALWAYS_INLINE; |
| 380 | |
| 381 | DISALLOW_COPY_AND_ASSIGN(MutatorMutex); |
| 382 | }; |
| 383 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 384 | // ConditionVariables allow threads to queue and sleep. Threads may then be resumed individually |
| 385 | // (Signal) or all at once (Broadcast). |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 386 | class ConditionVariable { |
| 387 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 388 | ConditionVariable(const char* name, Mutex& mutex); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 389 | ~ConditionVariable(); |
| 390 | |
Charles Munger | bcd16ee | 2018-10-22 13:03:23 -0700 | [diff] [blame] | 391 | // Requires the mutex to be held. |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 392 | void Broadcast(Thread* self); |
Charles Munger | bcd16ee | 2018-10-22 13:03:23 -0700 | [diff] [blame] | 393 | // Requires the mutex to be held. |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 394 | void Signal(Thread* self); |
| 395 | // TODO: No thread safety analysis on Wait and TimedWait as they call mutex operations via their |
| 396 | // pointer copy, thereby defeating annotalysis. |
| 397 | void Wait(Thread* self) NO_THREAD_SAFETY_ANALYSIS; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 398 | bool TimedWait(Thread* self, int64_t ms, int32_t ns) NO_THREAD_SAFETY_ANALYSIS; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 399 | // Variant of Wait that should be used with caution. Doesn't validate that no mutexes are held |
| 400 | // when waiting. |
| 401 | // TODO: remove this. |
| 402 | void WaitHoldingLocks(Thread* self) NO_THREAD_SAFETY_ANALYSIS; |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 403 | |
| 404 | private: |
Ian Rogers | 23055dc | 2013-04-18 16:29:16 -0700 | [diff] [blame] | 405 | const char* const name_; |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 406 | // The Mutex being used by waiters. It is an error to mix condition variables between different |
| 407 | // Mutexes. |
| 408 | Mutex& guard_; |
| 409 | #if ART_USE_FUTEXES |
| 410 | // A counter that is modified by signals and broadcasts. This ensures that when a waiter gives up |
Ian Rogers | d45f201 | 2012-11-28 11:46:23 -0800 | [diff] [blame] | 411 | // their Mutex and another thread takes it and signals, the waiting thread observes that sequence_ |
| 412 | // changed and doesn't enter the wait. Modified while holding guard_, but is read by futex wait |
| 413 | // without guard_ held. |
Ian Rogers | b122a4b | 2013-11-19 18:00:50 -0800 | [diff] [blame] | 414 | AtomicInteger sequence_; |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 415 | // Number of threads that have come into to wait, not the length of the waiters on the futex as |
Ian Rogers | 5bd97c4 | 2012-11-27 02:38:26 -0800 | [diff] [blame] | 416 | // waiters may have been requeued onto guard_. Guarded by guard_. |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 417 | volatile int32_t num_waiters_; |
Charles Munger | bcd16ee | 2018-10-22 13:03:23 -0700 | [diff] [blame] | 418 | |
| 419 | void RequeueWaiters(int32_t count); |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 420 | #else |
| 421 | pthread_cond_t cond_; |
| 422 | #endif |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 423 | DISALLOW_COPY_AND_ASSIGN(ConditionVariable); |
| 424 | }; |
| 425 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 426 | // Scoped locker/unlocker for a regular Mutex that acquires mu upon construction and releases it |
| 427 | // upon destruction. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 428 | class SCOPED_CAPABILITY MutexLock { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 429 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 430 | MutexLock(Thread* self, Mutex& mu) ACQUIRE(mu) : self_(self), mu_(mu) { |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 431 | mu_.ExclusiveLock(self_); |
| 432 | } |
| 433 | |
Mathieu Chartier | 4e2cb09 | 2015-07-22 16:17:51 -0700 | [diff] [blame] | 434 | ~MutexLock() RELEASE() { |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 435 | mu_.ExclusiveUnlock(self_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | private: |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 439 | Thread* const self_; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 440 | Mutex& mu_; |
| 441 | DISALLOW_COPY_AND_ASSIGN(MutexLock); |
| 442 | }; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 443 | |
| 444 | // Scoped locker/unlocker for a ReaderWriterMutex that acquires read access to mu upon |
| 445 | // construction and releases it upon destruction. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 446 | class SCOPED_CAPABILITY ReaderMutexLock { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 447 | public: |
Andreas Gampe | b486a98 | 2017-06-01 13:45:54 -0700 | [diff] [blame] | 448 | ALWAYS_INLINE ReaderMutexLock(Thread* self, ReaderWriterMutex& mu) ACQUIRE(mu); |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 449 | |
Andreas Gampe | b486a98 | 2017-06-01 13:45:54 -0700 | [diff] [blame] | 450 | ALWAYS_INLINE ~ReaderMutexLock() RELEASE(); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 451 | |
| 452 | private: |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 453 | Thread* const self_; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 454 | ReaderWriterMutex& mu_; |
| 455 | DISALLOW_COPY_AND_ASSIGN(ReaderMutexLock); |
| 456 | }; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 457 | |
| 458 | // Scoped locker/unlocker for a ReaderWriterMutex that acquires write access to mu upon |
| 459 | // construction and releases it upon destruction. |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 460 | class SCOPED_CAPABILITY WriterMutexLock { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 461 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 462 | WriterMutexLock(Thread* self, ReaderWriterMutex& mu) EXCLUSIVE_LOCK_FUNCTION(mu) : |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 463 | self_(self), mu_(mu) { |
| 464 | mu_.ExclusiveLock(self_); |
| 465 | } |
| 466 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 467 | ~WriterMutexLock() UNLOCK_FUNCTION() { |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 468 | mu_.ExclusiveUnlock(self_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | private: |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 472 | Thread* const self_; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 473 | ReaderWriterMutex& mu_; |
| 474 | DISALLOW_COPY_AND_ASSIGN(WriterMutexLock); |
| 475 | }; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 476 | |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 477 | } // namespace art |
| 478 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 479 | #endif // ART_RUNTIME_BASE_MUTEX_H_ |