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.cc17
1 files changed, 11 insertions, 6 deletions
diff --git a/runtime/base/mutex.cc b/runtime/base/mutex.cc
index 728dc842c2..ffc2168025 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
@@ -923,7 +928,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 +952,7 @@ bool ReaderWriterMutex::SharedTryLock(Thread* self) {
PLOG(FATAL) << "pthread_mutex_trylock failed for " << name_;
}
#endif
- RegisterAsLocked(self);
+ RegisterAsLocked(self, check);
AssertSharedHeld(self);
return true;
}