[compiler-rt] r314040 - [sanitizer] Replace thread id with GetThreadSelf
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 22 15:36:21 PDT 2017
Author: vitalybuka
Date: Fri Sep 22 15:36:21 2017
New Revision: 314040
URL: http://llvm.org/viewvc/llvm-project?rev=314040&view=rev
Log:
[sanitizer] Replace thread id with GetThreadSelf
This allows to avoid constructor parameter
Modified:
compiler-rt/trunk/lib/asan/asan_report.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc
Modified: compiler-rt/trunk/lib/asan/asan_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_report.cc?rev=314040&r1=314039&r2=314040&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_report.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_report.cc Fri Sep 22 15:36:21 2017
@@ -122,12 +122,8 @@ bool ParseFrameDescription(const char *f
// immediately after printing error report.
class ScopedInErrorReport {
public:
- static const u32 kUnclaimedTid = 0xfffffe;
- static_assert(kUnclaimedTid != kInvalidTid, "Must be different");
-
explicit ScopedInErrorReport(bool fatal = false)
- : error_report_lock_(GetCurrentTidOrInvalid()),
- halt_on_error_(fatal || flags()->halt_on_error) {
+ : halt_on_error_(fatal || flags()->halt_on_error) {
// Make sure the registry and sanitizer report mutexes are locked while
// we're printing an error report.
// We can lock them only here to avoid self-deadlock in case of
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=314040&r1=314039&r2=314040&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Fri Sep 22 15:36:21 2017
@@ -211,7 +211,7 @@ extern StaticSpinMutex CommonSanitizerRe
// Lock sanitizer error reporting and protects against nested errors.
class ScopedErrorReportLock {
public:
- explicit ScopedErrorReportLock(u32 current_tid);
+ ScopedErrorReportLock();
~ScopedErrorReportLock();
};
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc?rev=314040&r1=314039&r2=314040&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc Fri Sep 22 15:36:21 2017
@@ -286,21 +286,20 @@ void MaybeStartBackgroudThread() {
#endif
}
-static const u32 kUnclaimedTid = 0xfffffe;
-static atomic_uint32_t reporting_thread_tid = {kUnclaimedTid};
+static atomic_uintptr_t reporting_thread = {0};
-ScopedErrorReportLock::ScopedErrorReportLock(u32 current_tid) {
+ScopedErrorReportLock::ScopedErrorReportLock() {
+ uptr current = GetThreadSelf();
for (;;) {
- u32 expected_tid = kUnclaimedTid;
- if (current_tid == kUnclaimedTid ||
- atomic_compare_exchange_strong(&reporting_thread_tid, &expected_tid,
- current_tid, memory_order_relaxed)) {
- // We've claimed reporting_thread_tid_ so proceed.
+ uptr expected = 0;
+ if (atomic_compare_exchange_strong(&reporting_thread, &expected, current,
+ memory_order_relaxed)) {
+ // We've claimed reporting_thread so proceed.
CommonSanitizerReportMutex.Lock();
return;
}
- if (expected_tid == current_tid) {
+ if (expected == current) {
// This is either asynch signal or nested error during error reporting.
// Fail simple to avoid deadlocks in Report().
@@ -320,7 +319,7 @@ ScopedErrorReportLock::ScopedErrorReport
ScopedErrorReportLock::~ScopedErrorReportLock() {
CommonSanitizerReportMutex.Unlock();
- atomic_store_relaxed(&reporting_thread_tid, kUnclaimedTid);
+ atomic_store_relaxed(&reporting_thread, 0);
}
} // namespace __sanitizer
More information about the llvm-commits
mailing list