[compiler-rt] r216900 - tsan: address comments in r214912

Dmitry Vyukov dvyukov at google.com
Tue Sep 2 02:34:35 PDT 2014


Author: dvyukov
Date: Tue Sep  2 04:34:34 2014
New Revision: 216900

URL: http://llvm.org/viewvc/llvm-project?rev=216900&view=rev
Log:
tsan: address comments in r214912
See http://reviews.llvm.org/D4794


Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_thread_registry.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_thread_registry.h
    compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_clock.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_clock.h

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_thread_registry.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_thread_registry.cc?rev=216900&r1=216899&r2=216900&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_thread_registry.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_thread_registry.cc Tue Sep  2 04:34:34 2014
@@ -218,10 +218,6 @@ void ThreadRegistry::SetThreadNameByUser
   }
 }
 
-void ThreadRegistry::DetachThread(u32 tid) {
-  DetachThread(tid, 0);
-}
-
 void ThreadRegistry::DetachThread(u32 tid, void *arg) {
   BlockingMutexLock l(&mtx_);
   CHECK_LT(tid, n_contexts_);

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_thread_registry.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_thread_registry.h?rev=216900&r1=216899&r2=216900&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_thread_registry.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_thread_registry.h Tue Sep  2 04:34:34 2014
@@ -111,7 +111,6 @@ class ThreadRegistry {
 
   void SetThreadName(u32 tid, const char *name);
   void SetThreadNameByUserId(uptr user_id, const char *name);
-  void DetachThread(u32 tid);
   void DetachThread(u32 tid, void *arg);
   void JoinThread(u32 tid, void *arg);
   void FinishThread(u32 tid);

Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc?rev=216900&r1=216899&r2=216900&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc Tue Sep  2 04:34:34 2014
@@ -107,13 +107,13 @@ static void TestRegistry(ThreadRegistry
             registry->FindThread(HasUid, (void*)0x1234));
   // Detach and finish and join remaining threads.
   for (u32 i = 6; i <= 10; i++) {
-    registry->DetachThread(i);
+    registry->DetachThread(i, 0);
     registry->FinishThread(i);
   }
   for (u32 i = 0; i < new_tids.size(); i++) {
     u32 tid = new_tids[i];
     registry->StartThread(tid, 0, 0);
-    registry->DetachThread(tid);
+    registry->DetachThread(tid, 0);
     registry->FinishThread(tid);
   }
   CheckThreadQuantity(registry, exp_total, 1, 1);

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_clock.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_clock.cc?rev=216900&r1=216899&r2=216900&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_clock.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_clock.cc Tue Sep  2 04:34:34 2014
@@ -174,7 +174,7 @@ void ThreadClock::release(ClockCache *c,
   CPP_STAT_INC(StatClockRelease);
   // Check if we need to resize dst.
   if (dst->size_ < nclk_)
-    Resize(c, dst);
+    dst->Resize(c, nclk_);
 
   // Check if we had not acquired anything from other threads
   // since the last release on dst. If so, we need to update
@@ -221,7 +221,7 @@ void ThreadClock::ReleaseStore(ClockCach
 
   // Check if we need to resize dst.
   if (dst->size_ < nclk_)
-    Resize(c, dst);
+    dst->Resize(c, nclk_);
 
   if (dst->release_store_tid_ == tid_ &&
       dst->release_store_reused_ == reused_ &&
@@ -299,51 +299,51 @@ bool ThreadClock::IsAlreadyAcquired(cons
   return true;
 }
 
-void ThreadClock::Resize(ClockCache *c, SyncClock *dst) const {
+void SyncClock::Resize(ClockCache *c, uptr nclk) {
   CPP_STAT_INC(StatClockReleaseResize);
-  if (RoundUpTo(nclk_, ClockBlock::kClockCount) <=
-      RoundUpTo(dst->size_, ClockBlock::kClockCount)) {
+  if (RoundUpTo(nclk, ClockBlock::kClockCount) <=
+      RoundUpTo(size_, ClockBlock::kClockCount)) {
     // Growing within the same block.
     // Memory is already allocated, just increase the size.
-    dst->size_ = nclk_;
+    size_ = nclk;
     return;
   }
-  if (nclk_ <= ClockBlock::kClockCount) {
+  if (nclk <= ClockBlock::kClockCount) {
     // Grow from 0 to one-level table.
-    CHECK_EQ(dst->size_, 0);
-    CHECK_EQ(dst->tab_, 0);
-    CHECK_EQ(dst->tab_idx_, 0);
-    dst->size_ = nclk_;
-    dst->tab_idx_ = ctx->clock_alloc.Alloc(c);
-    dst->tab_ = ctx->clock_alloc.Map(dst->tab_idx_);
-    internal_memset(dst->tab_, 0, sizeof(*dst->tab_));
+    CHECK_EQ(size_, 0);
+    CHECK_EQ(tab_, 0);
+    CHECK_EQ(tab_idx_, 0);
+    size_ = nclk;
+    tab_idx_ = ctx->clock_alloc.Alloc(c);
+    tab_ = ctx->clock_alloc.Map(tab_idx_);
+    internal_memset(tab_, 0, sizeof(*tab_));
     return;
   }
   // Growing two-level table.
-  if (dst->size_ == 0) {
+  if (size_ == 0) {
     // Allocate first level table.
-    dst->tab_idx_ = ctx->clock_alloc.Alloc(c);
-    dst->tab_ = ctx->clock_alloc.Map(dst->tab_idx_);
-    internal_memset(dst->tab_, 0, sizeof(*dst->tab_));
-  } else if (dst->size_ <= ClockBlock::kClockCount) {
+    tab_idx_ = ctx->clock_alloc.Alloc(c);
+    tab_ = ctx->clock_alloc.Map(tab_idx_);
+    internal_memset(tab_, 0, sizeof(*tab_));
+  } else if (size_ <= ClockBlock::kClockCount) {
     // Transform one-level table to two-level table.
-    u32 old = dst->tab_idx_;
-    dst->tab_idx_ = ctx->clock_alloc.Alloc(c);
-    dst->tab_ = ctx->clock_alloc.Map(dst->tab_idx_);
-    internal_memset(dst->tab_, 0, sizeof(*dst->tab_));
-    dst->tab_->table[0] = old;
+    u32 old = tab_idx_;
+    tab_idx_ = ctx->clock_alloc.Alloc(c);
+    tab_ = ctx->clock_alloc.Map(tab_idx_);
+    internal_memset(tab_, 0, sizeof(*tab_));
+    tab_->table[0] = old;
   }
   // At this point we have first level table allocated.
   // Add second level tables as necessary.
-  for (uptr i = RoundUpTo(dst->size_, ClockBlock::kClockCount);
-      i < nclk_; i += ClockBlock::kClockCount) {
+  for (uptr i = RoundUpTo(size_, ClockBlock::kClockCount);
+      i < nclk; i += ClockBlock::kClockCount) {
     u32 idx = ctx->clock_alloc.Alloc(c);
     ClockBlock *cb = ctx->clock_alloc.Map(idx);
     internal_memset(cb, 0, sizeof(*cb));
-    CHECK_EQ(dst->tab_->table[i/ClockBlock::kClockCount], 0);
-    dst->tab_->table[i/ClockBlock::kClockCount] = idx;
+    CHECK_EQ(tab_->table[i/ClockBlock::kClockCount], 0);
+    tab_->table[i/ClockBlock::kClockCount] = idx;
   }
-  dst->size_ = nclk_;
+  size_ = nclk;
 }
 
 // Sets a single element in the vector clock.
@@ -368,17 +368,18 @@ void ThreadClock::DebugDump(int(*printf)
       tid_, reused_, last_acquire_);
 }
 
-SyncClock::SyncClock() {
-  tab_ = 0;
-  tab_idx_ = 0;
-  size_ = 0;
-  release_store_tid_ = kInvalidTid;
-  release_store_reused_ = 0;
+SyncClock::SyncClock()
+    : release_store_tid_(kInvalidTid)
+    , release_store_reused_()
+    , tab_()
+    , tab_idx_()
+    , size_() {
   for (uptr i = 0; i < kDirtyTids; i++)
     dirty_tids_[i] = kInvalidTid;
 }
 
 SyncClock::~SyncClock() {
+  // Reset must be called before dtor.
   CHECK_EQ(size_, 0);
   CHECK_EQ(tab_, 0);
   CHECK_EQ(tab_idx_, 0);

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_clock.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_clock.h?rev=216900&r1=216899&r2=216900&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_clock.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_clock.h Tue Sep  2 04:34:34 2014
@@ -54,6 +54,7 @@ class SyncClock {
     return elem(tid).epoch;
   }
 
+  void Resize(ClockCache *c, uptr nclk);
   void Reset(ClockCache *c);
 
   void DebugDump(int(*printf)(const char *s, ...));
@@ -121,7 +122,6 @@ struct ThreadClock {
 
   bool IsAlreadyAcquired(const SyncClock *src) const;
   void UpdateCurrentThread(SyncClock *dst) const;
-  void Resize(ClockCache *c, SyncClock *dst) const;
 };
 
 }  // namespace __tsan





More information about the llvm-commits mailing list