summaryrefslogtreecommitdiff
path: root/runtime/base/mutex.h
diff options
context:
space:
mode:
author Hans Boehm <hboehm@google.com> 2022-09-14 22:45:40 +0000
committer Hans Boehm <hboehm@google.com> 2022-10-12 22:41:25 +0000
commitfd20a745227aa7cae7a08728bb29e5bfce64ea87 (patch)
tree3a39bacc9c52bfd68abb4976b083359636d8fc78 /runtime/base/mutex.h
parent40bc9dc50978a7e8a7d41f551adef02ad2546254 (diff)
Revert^2 "Thread suspension cleanup and deadlock fix"
This reverts commit 7c8835df16147b9096dd4c9380ab4b5f700ea17d. PS1 is identical to aosp/2171862 . PS2 makes the following significant changes: 1) Avoid inflating locks from the thread dumping checkpoint Run() method. This violates the repeatedly stated claim that checkpoint Run() methods don't suspend threads. This requires that we print object addresses in thread dumps in some cases in which we were previously able to give hashcodes instead. 2) For debug builds, check that we do not acquire a higher level lock in checkpoint Run() methods, thus enforcing that previously stated property. (Lokesh suggested this, and I think it's a great idea. But it requires changes 4-6 below.) 3) Add a bit more justification that RunCheckpoint cannot result in circular suspend requests. 4) For now, allow an explicit override of (2) for ddms code in which it would otherwise fail. This should be fixed later. 5) Raise the level of monitor locks, to correctly reflect the fact that they may be held while much of the runtime is executed. 6) (5) was in conflict with monitor deflation acquiring a monitor lock after acquiring the monitor list lock. But this failure is spurious, both because it is a TryLock acquisition that can't possibly contributed to a deadlock, and secondly because it conflates all monitor locks, and an actual deadlock is probably not possible anyway. Leverage the former and add a facility to avoid checking for safe TryLock calls. (1) Should fix the one failure I managed to debug after the last submission attempt. Hopefully it also accounts for the others. PS3, PS5, PS6: Trivial corrections and cleanups PS4, PS7, PS8: Rebase Test: Build and boot AOSP, Treehugger Bug: 240742796 Bug: 203363895 Bug: 238032384 Change-Id: I80d441ebe21bb30b586131f7d22b7f2797f2c45f
Diffstat (limited to 'runtime/base/mutex.h')
-rw-r--r--runtime/base/mutex.h14
1 files changed, 9 insertions, 5 deletions
diff --git a/runtime/base/mutex.h b/runtime/base/mutex.h
index 87e9525557..407effeab6 100644
--- a/runtime/base/mutex.h
+++ b/runtime/base/mutex.h
@@ -103,10 +103,11 @@ class BaseMutex {
BaseMutex(const char* name, LockLevel level);
virtual ~BaseMutex();
- // Add this mutex to those owned by self, and perform appropriate checking.
- // For this call only, self may also be another suspended thread.
- void RegisterAsLocked(Thread* self);
- void RegisterAsLockedImpl(Thread* self, LockLevel level);
+ // Add this mutex to those owned by self, and optionally perform lock order checking. Caller
+ // may wish to disable checking for trylock calls that cannot result in deadlock. For this call
+ // only, self may also be another suspended thread.
+ void RegisterAsLocked(Thread* self, bool check = kDebugLocking);
+ void RegisterAsLockedImpl(Thread* self, LockLevel level, bool check);
void RegisterAsUnlocked(Thread* self);
void RegisterAsUnlockedImpl(Thread* self, LockLevel level);
@@ -183,7 +184,10 @@ class LOCKABLE Mutex : public BaseMutex {
void ExclusiveLock(Thread* self) ACQUIRE();
void Lock(Thread* self) ACQUIRE() { ExclusiveLock(self); }
- // Returns true if acquires exclusive access, false otherwise.
+ // Returns true if acquires exclusive access, false otherwise. The `check` argument specifies
+ // whether lock level checking should be performed. Should be defaulted unless we are using
+ // TryLock instead of Lock for deadlock avoidance.
+ template<bool check = kDebugLocking>
bool ExclusiveTryLock(Thread* self) TRY_ACQUIRE(true);
bool TryLock(Thread* self) TRY_ACQUIRE(true) { return ExclusiveTryLock(self); }
// Equivalent to ExclusiveTryLock, but retry for a short period before giving up.