summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2014-02-28 10:48:13 +0000
committerDmitry Vyukov <dvyukov@google.com>2014-02-28 10:48:13 +0000
commit6cfab724ec4ef103d0c632f5125559182cadf20b (patch)
tree8647f6a5da706ceddfc01fe4eb38cd3e36420b39 /compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc
parent371639ea1f0b4e9c3c16a2d5562c993eac2749cf (diff)
downloadbcm5719-llvm-6cfab724ec4ef103d0c632f5125559182cadf20b.tar.gz
bcm5719-llvm-6cfab724ec4ef103d0c632f5125559182cadf20b.zip
tsan: refactor deadlock detector
Introduce DDetector interface between the tool and the DD itself. It will help to experiment with other DD implementation, as well as reuse DD in other tools. llvm-svn: 202485
Diffstat (limited to 'compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc')
-rw-r--r--compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc14
1 files changed, 12 insertions, 2 deletions
diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc
index f41ed50dde0..abf68ca3b2b 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc
+++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc
@@ -83,13 +83,14 @@ struct OnStartedArgs {
};
void ThreadContext::OnStarted(void *arg) {
+ Context *ctx = CTX();
OnStartedArgs *args = static_cast<OnStartedArgs*>(arg);
thr = args->thr;
// RoundUp so that one trace part does not contain events
// from different threads.
epoch0 = RoundUp(epoch1 + 1, kTracePartSize);
epoch1 = (u64)-1;
- new(thr) ThreadState(CTX(), tid, unique_id,
+ new(thr) ThreadState(ctx, tid, unique_id,
epoch0, args->stk_addr, args->stk_size, args->tls_addr, args->tls_size);
#ifndef TSAN_GO
thr->shadow_stack = &ThreadTrace(thr->tid)->shadow_stack[0];
@@ -106,6 +107,10 @@ void ThreadContext::OnStarted(void *arg) {
#ifndef TSAN_GO
AllocatorThreadStart(thr);
#endif
+ if (flags()->detect_deadlocks) {
+ thr->dd_pt = ctx->dd->CreatePhysicalThread();
+ thr->dd_lt = ctx->dd->CreateLogicalThread(unique_id);
+ }
thr->fast_synch_epoch = epoch0;
AcquireImpl(thr, 0, &sync);
thr->fast_state.SetHistorySize(flags()->history_size);
@@ -122,6 +127,7 @@ void ThreadContext::OnStarted(void *arg) {
}
void ThreadContext::OnFinished() {
+ Context *ctx = CTX();
if (!detached) {
thr->fast_state.IncrementEpoch();
// Can't increment epoch w/o writing to the trace as well.
@@ -130,11 +136,15 @@ void ThreadContext::OnFinished() {
}
epoch1 = thr->fast_state.epoch();
+ if (flags()->detect_deadlocks) {
+ ctx->dd->DestroyPhysicalThread(thr->dd_pt);
+ ctx->dd->DestroyLogicalThread(thr->dd_lt);
+ }
#ifndef TSAN_GO
AllocatorThreadFinish(thr);
#endif
thr->~ThreadState();
- StatAggregate(CTX()->stat, thr->stat);
+ StatAggregate(ctx->stat, thr->stat);
thr = 0;
}
OpenPOWER on IntegriCloud