diff options
author | Kostya Serebryany <kcc@google.com> | 2014-03-13 13:21:30 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2014-03-13 13:21:30 +0000 |
commit | 9cdcf37ef1c7cf59dea0fecb1938f77d60324d70 (patch) | |
tree | f19d71e2ab53ddca818194f85bdef0c58a1f6dc9 /lib/sanitizer_common/sanitizer_deadlock_detector1.cc | |
parent | c5dc470eacfb0aab04b6737573e099b46f033e1b (diff) |
[sanitizer] in bitvector-based deadlock detector split onLock into onLockBefore and onLockAfter hooks
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@203796 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_deadlock_detector1.cc')
-rw-r--r-- | lib/sanitizer_common/sanitizer_deadlock_detector1.cc | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/lib/sanitizer_common/sanitizer_deadlock_detector1.cc b/lib/sanitizer_common/sanitizer_deadlock_detector1.cc index adf6bd336..2f27b3cc5 100644 --- a/lib/sanitizer_common/sanitizer_deadlock_detector1.cc +++ b/lib/sanitizer_common/sanitizer_deadlock_detector1.cc @@ -98,24 +98,15 @@ void DD::MutexEnsureID(DDLogicalThread *lt, DDMutex *m) { void DD::MutexBeforeLock(DDCallback *cb, DDMutex *m, bool wlock) { -} - -void DD::MutexAfterLock(DDCallback *cb, DDMutex *m, bool wlock, bool trylock) { DDLogicalThread *lt = cb->lt; - if (dd.onFirstLock(<->dd, m->id)) - return; + if (lt->dd.empty()) return; // This will be the first lock held by lt. SpinMutexLock lk(&mtx); MutexEnsureID(lt, m); - if (wlock) // Only a recursive rlock may be held. - CHECK(!dd.isHeld(<->dd, m->id)); - // Printf("T%d MutexLock: %zx\n", thr->tid, s->deadlock_detector_id); - bool has_deadlock = trylock - ? dd.onTryLock(<->dd, m->id) - : dd.onLock(<->dd, m->id); - if (has_deadlock) { + if (dd.isHeld(<->dd, m->id)) + return; // FIXME: allow this only for recursive locks. + if (dd.onLockBefore(<->dd, m->id)) { uptr path[10]; - uptr len = dd.findPathToHeldLock(<->dd, m->id, - path, ARRAY_SIZE(path)); + uptr len = dd.findPathToLock(<->dd, m->id, path, ARRAY_SIZE(path)); CHECK_GT(len, 0U); // Hm.. cycle of 10 locks? I'd like to see that. lt->report_pending = true; DDReport *rep = <->rep; @@ -131,9 +122,24 @@ void DD::MutexAfterLock(DDCallback *cb, DDMutex *m, bool wlock, bool trylock) { } } +void DD::MutexAfterLock(DDCallback *cb, DDMutex *m, bool wlock, bool trylock) { + DDLogicalThread *lt = cb->lt; + // Printf("T%p MutexLock: %zx\n", lt, m->id); + if (dd.onFirstLock(<->dd, m->id)) + return; + SpinMutexLock lk(&mtx); + MutexEnsureID(lt, m); + if (wlock) // Only a recursive rlock may be held. + CHECK(!dd.isHeld(<->dd, m->id)); + bool edge_added = + trylock ? dd.onTryLock(<->dd, m->id) : dd.onLockAfter(<->dd, m->id); + if (edge_added) { + // Printf("Edge added\n"); + } +} + void DD::MutexBeforeUnlock(DDCallback *cb, DDMutex *m, bool wlock) { - // Printf("T%d MutexUnlock: %zx; recursion %d\n", thr->tid, - // s->deadlock_detector_id, s->recursion); + // Printf("T%p MutexUnLock: %zx\n", cb->lt, m->id); dd.onUnlock(&cb->lt->dd, m->id); } |