diff options
author | Kostya Serebryany <kcc@google.com> | 2014-02-13 12:39:21 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2014-02-13 12:39:21 +0000 |
commit | d0caa6e878b2cd55343aaff572a96453ae4d9a64 (patch) | |
tree | 55f51da52fcad34d71f056018f897e5eb9c9ec7b /lib/sanitizer_common/sanitizer_deadlock_detector.h | |
parent | 95e0ee58ffc6afc09f0a7a29b4a8fe02c74297bc (diff) |
[sanitizer] address some of the dvyukov's comments on previous commits
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@201322 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_deadlock_detector.h')
-rw-r--r-- | lib/sanitizer_common/sanitizer_deadlock_detector.h | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/sanitizer_common/sanitizer_deadlock_detector.h b/lib/sanitizer_common/sanitizer_deadlock_detector.h index 4f3f87d3b..66ec0186d 100644 --- a/lib/sanitizer_common/sanitizer_deadlock_detector.h +++ b/lib/sanitizer_common/sanitizer_deadlock_detector.h @@ -30,10 +30,12 @@ class DeadlockDetectorTLS { public: // No CTOR. void clear() { n_locks_ = 0; } + void addLock(uptr node) { CHECK_LT(n_locks_, ARRAY_SIZE(locks_)); locks_[n_locks_++] = node; } + void removeLock(uptr node) { CHECK_NE(n_locks_, 0U); for (sptr i = n_locks_ - 1; i >= 0; i--) { @@ -45,7 +47,9 @@ class DeadlockDetectorTLS { } CHECK(0); } + uptr numLocks() const { return n_locks_; } + uptr getLock(uptr idx) const { CHECK_LT(idx, n_locks_); return locks_[idx]; @@ -67,6 +71,7 @@ class DeadlockDetector { typedef BV BitVector; uptr size() const { return g_.size(); } + // No CTOR. void clear() { current_epoch_ = 0; @@ -90,7 +95,7 @@ class DeadlockDetector { return getAvailableNode(data); } // We are out of vacant nodes. Flush and increment the current_epoch_. - uptr new_epoch = current_epoch_ + BV::kSize; + uptr new_epoch = current_epoch_ + size(); clear(); current_epoch_ = new_epoch; available_nodes_.setAll(); @@ -131,23 +136,28 @@ class DeadlockDetector { private: void check_idx(uptr idx) const { CHECK_LT(idx, size()); } + void check_node(uptr node) const { CHECK_GE(node, size()); CHECK_EQ(current_epoch_, node / size() * size()); } + uptr indexToNode(uptr idx) { check_idx(idx); - return idx | current_epoch_; + return idx + current_epoch_; } + uptr nodeToIndex(uptr node) { check_node(node); return node % size(); } + uptr getAvailableNode(uptr data) { uptr idx = available_nodes_.getAndClearFirstOne(); data_[idx] = data; return indexToNode(idx); } + uptr current_epoch_; BV available_nodes_; BV recycled_nodes_; |