diff options
author | 2024-11-11 16:05:17 -0800 | |
---|---|---|
committer | 2024-11-12 16:19:02 +0000 | |
commit | dc42d4ed36d22433c8dc5f68a51e9f2acd47f34d (patch) | |
tree | b05e0b9940eb983eb049c0c19284a2e7993f5edf /runtime/base/mutex.cc | |
parent | 3051a5e03f32ca7aaae6041025ec60f90d41e34c (diff) |
Clarify GetExclusiveOwner() semantics
It is inherently unreliable unless the mutex is held.
Contention reports may err if the mutex has already been, or is
about to be, released.
Fixing this would require including exclusive_owner_ in the atomic
operation part of lock/unlock operations, which would require us to rely
on wider atomic operations on the fast path. So just document it better.
Bug: 377068860
Test: Treehugger
Change-Id: Id2be3dca573656e7aa10cf975f9a6c9275cd3541
Diffstat (limited to 'runtime/base/mutex.cc')
-rw-r--r-- | runtime/base/mutex.cc | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/runtime/base/mutex.cc b/runtime/base/mutex.cc index 0abe9667f8..26a665bd41 100644 --- a/runtime/base/mutex.cc +++ b/runtime/base/mutex.cc @@ -463,6 +463,7 @@ void Mutex::ExclusiveLock(Thread* self) { done = state_and_contenders_.CompareAndSetWeakAcquire(cur_state, cur_state | kHeldMask); } else { // Failed to acquire, hang up. + // We don't hold the mutex: GetExclusiveOwnerTid() is usually, but not always, correct. ScopedContentionRecorder scr(this, SafeGetTid(self), GetExclusiveOwnerTid()); // Empirically, it appears important to spin again each time through the loop; if we // bother to go to sleep and wake up, we should be fairly persistent in trying for the |