This is an archive of the discontinued LLVM Phabricator instance.

sanitizer_common: replace RWMutex/BlockingMutex with Mutex
ClosedPublic

Authored by dvyukov on Jul 28 2021, 12:59 AM.

Details

Summary

Mutex supports reader access, OS blocking, spinning,
portable and smaller than BlockingMutex.
Overall it's supposed to be better than RWMutex/BlockingMutex.
Replace RWMutex/BlockingMutex with Mutex.

Diff Detail

Event Timeline

dvyukov created this revision.Jul 28 2021, 12:59 AM
dvyukov requested review of this revision.Jul 28 2021, 12:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 28 2021, 12:59 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
dvyukov updated this revision to Diff 362296.Jul 28 2021, 1:00 AM

also remove BlockingMutex test.

melver added inline comments.Jul 28 2021, 2:45 AM
compiler-rt/lib/sanitizer_common/sanitizer_mutex.h
345

I think there are a few locations which rely on this constructor. It compiles, but Mutex's constructor takes MutexType and LINKER_INITIALIZED==MutexInvalid.

% git grep 'BlockingMutex.*LINKER_INITIALIZED'
compiler-rt/lib/asan/asan_globals.cpp:static BlockingMutex mu_for_globals(LINKER_INITIALIZED);
compiler-rt/lib/asan/asan_report.cpp:static BlockingMutex error_message_buf_mutex(LINKER_INITIALIZED);
compiler-rt/lib/asan/asan_stats.cpp:static BlockingMutex print_lock(LINKER_INITIALIZED);
compiler-rt/lib/asan/asan_stats.cpp:static BlockingMutex dead_threads_stats_lock(LINKER_INITIALIZED);
compiler-rt/lib/asan/asan_thread.cpp:static BlockingMutex mu_for_thread_context(LINKER_INITIALIZED);
compiler-rt/lib/cfi/cfi.cpp:BlockingMutex shadow_update_lock(LINKER_INITIALIZED);
compiler-rt/lib/cfi/cfi.cpp:static BlockingMutex interceptor_init_lock(LINKER_INITIALIZED);
compiler-rt/lib/lsan/lsan_common.cpp:BlockingMutex global_mutex(LINKER_INITIALIZED);
compiler-rt/lib/memprof/memprof_stats.cpp:static BlockingMutex print_lock(LINKER_INITIALIZED);
compiler-rt/lib/memprof/memprof_stats.cpp:static BlockingMutex dead_threads_stats_lock(LINKER_INITIALIZED);
compiler-rt/lib/memprof/memprof_thread.cpp:static BlockingMutex mu_for_thread_context(LINKER_INITIALIZED);
compiler-rt/lib/sanitizer_common/sanitizer_coverage_fuchsia.cpp:  BlockingMutex setup_lock_ = BlockingMutex(LINKER_INITIALIZED);
compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cpp:  //   BlockingMutex::BlockingMutex() : BlockingMutex(LINKER_INITIALIZED) {}
compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp:static BlockingMutex syslog_lock(LINKER_INITIALIZED);
compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp:static BlockingMutex crashreporter_info_mutex(LINKER_INITIALIZED);
compiler-rt/lib/sanitizer_common/tests/sanitizer_mutex_test.cpp:  BlockingMutex *mtx = new(mtxmem) BlockingMutex(LINKER_INITIALIZED);
compiler-rt/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cpp:static BlockingMutex tctx_allocator_lock(LINKER_INITIALIZED)

The cleanest would probably to just change all them to use the default constructor which is now constexpr.

dvyukov updated this revision to Diff 362327.Jul 28 2021, 4:16 AM

rebase to main HEAD

dvyukov added inline comments.Jul 28 2021, 4:24 AM
compiler-rt/lib/sanitizer_common/sanitizer_mutex.h
345

Very good point.
I've sent 2 other changes, see "Stack" section.

melver accepted this revision.Jul 28 2021, 5:58 AM
melver added inline comments.
compiler-rt/lib/sanitizer_common/sanitizer_mutex.h
375

Perhaps turn this into a TODO / FIXME so it shows up in 'git grep TODO' and less likely to be forgotten.

I assume this will disappear soon?

( s/Temporal/Temporary/, s/typedef's/typedefs/ )

This revision is now accepted and ready to land.Jul 28 2021, 5:58 AM
dvyukov updated this revision to Diff 362354.Jul 28 2021, 6:06 AM

improved TODO comment

dvyukov marked an inline comment as done.Jul 28 2021, 6:08 AM
dvyukov added inline comments.
compiler-rt/lib/sanitizer_common/sanitizer_mutex.h
375

I assume this will disappear soon?

Yes, I will resolve it once this change puts down root.
It's not a no-op change, so has some chances of being reverted.

This revision was landed with ongoing or failed builds.Jul 28 2021, 6:10 AM
This revision was automatically updated to reflect the committed changes.
dvyukov marked an inline comment as done.