Add RWMutex Downgrade() and ExclusiveTryLock()
These are both motivated by GC requirements. This adds only the
implementations and simple unit tests, not the client code that uses
these..
This also fixes some related testing issues:
1) Assert...Held() functions are not a good primitive for testing,
since they can hide compile-time thread-safety analysis issues, and
do not check anything in non-debug builds. Reduce their abuse.
2) The ASSERT gtest macros do not play well with thread-safety analysis,
since they introduce potentially problematic control flow that
violates locking properties. Add DEFERRED_ASSERT versions of a few
that avoid these issues, at the cost of slightly less clear, but
equally informative, failure messages.
NO_THREAD_SAFETY_ANALYSIS is an alternative for (2), whose use we reduce
here. NO_THREAD_SAFETY_ANALYSIS would hide all bugs in thread-safety
annotations. Mutex tests should help catch those as well.
This is needed to fix b/463464286. By itself, it affects only testing
behavior.
The pthreads implementation of Downgrade requires a second mutex,
since pthread_rwlock does not impose similar functionality. This
slows down the writer lock implementation.
I attempted to test the non-futex implementation, and this fixes
a couple of unrelated issues there. But the existence of those other
issues suggests that at least some ART runtime code hasn't even been
compiled without ART_USE_FUTEXES in ages. I don't think the above
slowdown can possibly be an issue.
Flag: EXEMPT BUGFIX
Test: m test-art-host-gtest-art_runtime_tests
Test: Manually test output from failed DEFERRED_ASSERT
Test: Manually enable non-futex code, with very partial success
Bug: 305779657
Bug: 463464286
Change-Id: I2912dc7fc4a2bf0853f0b5bf60c94ba63a56dd31
4 files changed