diff options
author | Vitaly Buka <vitalybuka@google.com> | 2017-09-22 22:36:21 +0000 |
---|---|---|
committer | Vitaly Buka <vitalybuka@google.com> | 2017-09-22 22:36:21 +0000 |
commit | 4365a0449cc7cba181357669774caf835f2ef9dd (patch) | |
tree | e1c6f0217c6714d6b602a163f1a828a8651e225c /lib/sanitizer_common/sanitizer_common_libcdep.cc | |
parent | 9b376627e371c9d879a8ba4d38aaa0638c9f0d58 (diff) |
[sanitizer] Replace thread id with GetThreadSelf
This allows to avoid constructor parameter
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@314040 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_common_libcdep.cc')
-rw-r--r-- | lib/sanitizer_common/sanitizer_common_libcdep.cc | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/lib/sanitizer_common/sanitizer_common_libcdep.cc b/lib/sanitizer_common/sanitizer_common_libcdep.cc index ce6bff447..b10eaeb96 100644 --- a/lib/sanitizer_common/sanitizer_common_libcdep.cc +++ b/lib/sanitizer_common/sanitizer_common_libcdep.cc @@ -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::ScopedErrorReportLock(u32 current_tid) { ScopedErrorReportLock::~ScopedErrorReportLock() { CommonSanitizerReportMutex.Unlock(); - atomic_store_relaxed(&reporting_thread_tid, kUnclaimedTid); + atomic_store_relaxed(&reporting_thread, 0); } } // namespace __sanitizer |