From 509999ec03149592bdc19c4c8fa7b142605dbf59 Mon Sep 17 00:00:00 2001 From: Dan Melnic Date: Tue, 22 Oct 2019 16:36:43 -0700 Subject: [PATCH] Add annotate_ignore_thread_sanitizer_guard class Summary: Add `annotate_ignore_thread_sanitizer_guard` class. (Note: this ignores all push blocking failures!) Reviewed By: yfeldblum Differential Revision: D18045913 fbshipit-source-id: 39113e8df3deef3374a3c44246bc55a156bc4d8d --- folly/detail/AtFork.cpp | 11 ++--------- folly/synchronization/SanitizeThread.h | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/folly/detail/AtFork.cpp b/folly/detail/AtFork.cpp index 69639799fa9..eb6daac00ce 100644 --- a/folly/detail/AtFork.cpp +++ b/folly/detail/AtFork.cpp @@ -77,15 +77,8 @@ class AtForkList { // so we just enable ignores for everything // while handling the child callbacks // This might still be an issue if we do not exec right away - annotate_ignore_reads_begin(__FILE__, __LINE__); - annotate_ignore_writes_begin(__FILE__, __LINE__); - annotate_ignore_sync_begin(__FILE__, __LINE__); - - auto reenableAnnotationsGuard = folly::makeGuard([] { - annotate_ignore_reads_end(__FILE__, __LINE__); - annotate_ignore_writes_end(__FILE__, __LINE__); - annotate_ignore_sync_end(__FILE__, __LINE__); - }); + annotate_ignore_thread_sanitizer_guard g(__FILE__, __LINE__); + auto& tasks = instance().tasks; for (auto& task : tasks) { task.child(); diff --git a/folly/synchronization/SanitizeThread.h b/folly/synchronization/SanitizeThread.h index c733c94a7b9..d1d11607580 100644 --- a/folly/synchronization/SanitizeThread.h +++ b/folly/synchronization/SanitizeThread.h @@ -189,4 +189,30 @@ FOLLY_ALWAYS_INLINE static void annotate_ignore_sync_end(const char* f, int l) { detail::annotate_ignore_sync_end_impl(f, l); } } + +class annotate_ignore_thread_sanitizer_guard { + public: + annotate_ignore_thread_sanitizer_guard(const char* file, int line) + : file_(file), line_(line) { + annotate_ignore_reads_begin(file_, line_); + annotate_ignore_writes_begin(file_, line_); + annotate_ignore_sync_begin(file_, line_); + } + + annotate_ignore_thread_sanitizer_guard( + const annotate_ignore_thread_sanitizer_guard&) = delete; + annotate_ignore_thread_sanitizer_guard& operator=( + const annotate_ignore_thread_sanitizer_guard&) = delete; + + ~annotate_ignore_thread_sanitizer_guard() { + annotate_ignore_reads_end(file_, line_); + annotate_ignore_writes_end(file_, line_); + annotate_ignore_sync_end(file_, line_); + } + + private: + const char* file_; + int line_; +}; + } // namespace folly