diff options
author | Kostya Serebryany <kcc@google.com> | 2014-02-28 11:56:14 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2014-02-28 11:56:14 +0000 |
commit | fe3da75bd71f570f6e07a371a30b4dec56a29245 (patch) | |
tree | 0ca75a9d431cb79e2f11df8ad977ba5ee33a4f3e /lib/sanitizer_common/sanitizer_deadlock_detector.h | |
parent | f22c748eb0714938853cab966e2a3eb61276a5fc (diff) |
[sanitizer] speedup deadlock detector for the case when we acquire the first lock in a thread
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@202492 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 | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/sanitizer_common/sanitizer_deadlock_detector.h b/lib/sanitizer_common/sanitizer_deadlock_detector.h index 318288e66..68cd1a532 100644 --- a/lib/sanitizer_common/sanitizer_deadlock_detector.h +++ b/lib/sanitizer_common/sanitizer_deadlock_detector.h @@ -42,6 +42,8 @@ class DeadlockDetectorTLS { epoch_ = 0; } + bool empty() const { return bv_.empty(); } + void ensureCurrentEpoch(uptr current_epoch) { if (epoch_ == current_epoch) return; bv_.clear(); @@ -157,6 +159,18 @@ class DeadlockDetector { return false; } + // Returns true iff dtls is empty (no locks are currently held) and we can + // add the node to the currently held locks w/o chanding the global state. + // This operation is thread-safe as it only touches the dtls. + bool onFirstLock(DeadlockDetectorTLS<BV> *dtls, uptr node) { + if (!dtls->empty()) return false; + if (dtls->getEpoch() && dtls->getEpoch() == nodeToEpoch(node)) { + dtls->addLock(nodeToIndexUnchecked(node), nodeToEpoch(node)); + return true; + } + return false; + } + // Finds a path between the lock 'cur_node' (which is currently held in dtls) // and some other currently held lock, returns the length of the path // or 0 on failure. @@ -173,8 +187,8 @@ class DeadlockDetector { return res; } - // Handle the unlock event. This operation is thread-safe - // as it only touches the dtls. + // Handle the unlock event. + // This operation is thread-safe as it only touches the dtls. void onUnlock(DeadlockDetectorTLS<BV> *dtls, uptr node) { if (dtls->getEpoch() == nodeToEpoch(node)) dtls->removeLock(nodeToIndexUnchecked(node)); |