summaryrefslogtreecommitdiff
path: root/runtime/base/mutex.cc
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/base/mutex.cc')
-rw-r--r--runtime/base/mutex.cc28
1 files changed, 17 insertions, 11 deletions
diff --git a/runtime/base/mutex.cc b/runtime/base/mutex.cc
index 728dc842c2..5b74bee279 100644
--- a/runtime/base/mutex.cc
+++ b/runtime/base/mutex.cc
@@ -246,11 +246,12 @@ void BaseMutex::DumpAll(std::ostream& os) {
}
void BaseMutex::CheckSafeToWait(Thread* self) {
- if (self == nullptr) {
- CheckUnattachedThread(level_);
+ if (!kDebugLocking) {
return;
}
- if (kDebugLocking) {
+ if (self == nullptr) {
+ CheckUnattachedThread(level_);
+ } else {
CHECK(self->GetHeldMutex(level_) == this || level_ == kMonitorLock)
<< "Waiting on unacquired mutex: " << name_;
bool bad_mutexes_held = false;
@@ -570,6 +571,7 @@ bool Mutex::IsDumpFrequent(Thread* thread, uint64_t try_times) {
}
}
+template <bool kCheck>
bool Mutex::ExclusiveTryLock(Thread* self) {
DCHECK(self == nullptr || self == Thread::Current());
if (kDebugLocking && !recursive_) {
@@ -600,7 +602,7 @@ bool Mutex::ExclusiveTryLock(Thread* self) {
#endif
DCHECK_EQ(GetExclusiveOwnerTid(), 0);
exclusive_owner_.store(SafeGetTid(self), std::memory_order_relaxed);
- RegisterAsLocked(self);
+ RegisterAsLocked(self, kCheck);
}
recursion_count_++;
if (kDebugLocking) {
@@ -611,6 +613,9 @@ bool Mutex::ExclusiveTryLock(Thread* self) {
return true;
}
+template bool Mutex::ExclusiveTryLock<false>(Thread* self);
+template bool Mutex::ExclusiveTryLock<true>(Thread* self);
+
bool Mutex::ExclusiveTryLockWithSpinning(Thread* self) {
// Spin a small number of times, since this affects our ability to respond to suspension
// requests. We spin repeatedly only if the mutex repeatedly becomes available and unavailable
@@ -717,11 +722,12 @@ void Mutex::ExclusiveUnlock(Thread* self) {
}
void Mutex::Dump(std::ostream& os) const {
- os << (recursive_ ? "recursive " : "non-recursive ")
- << name_
- << " level=" << static_cast<int>(level_)
- << " rec=" << recursion_count_
- << " owner=" << GetExclusiveOwnerTid() << " ";
+ os << (recursive_ ? "recursive " : "non-recursive ") << name_
+ << " level=" << static_cast<int>(level_) << " rec=" << recursion_count_
+#if ART_USE_FUTEXES
+ << " state_and_contenders = " << std::hex << state_and_contenders_ << std::dec
+#endif
+ << " owner=" << GetExclusiveOwnerTid() << " ";
DumpContention(os);
}
@@ -923,7 +929,7 @@ void ReaderWriterMutex::HandleSharedLockContention(Thread* self, int32_t cur_sta
}
#endif
-bool ReaderWriterMutex::SharedTryLock(Thread* self) {
+bool ReaderWriterMutex::SharedTryLock(Thread* self, bool check) {
DCHECK(self == nullptr || self == Thread::Current());
#if ART_USE_FUTEXES
bool done = false;
@@ -947,7 +953,7 @@ bool ReaderWriterMutex::SharedTryLock(Thread* self) {
PLOG(FATAL) << "pthread_mutex_trylock failed for " << name_;
}
#endif
- RegisterAsLocked(self);
+ RegisterAsLocked(self, check);
AssertSharedHeld(self);
return true;
}