diff options
author | Kuba Brecka <kuba.brecka@gmail.com> | 2015-11-04 15:09:14 +0000 |
---|---|---|
committer | Kuba Brecka <kuba.brecka@gmail.com> | 2015-11-04 15:09:14 +0000 |
commit | a1186b828ffb1b796b067a3d46fcc8e827006a5f (patch) | |
tree | 4461489907c97bee51186412cba23a600b35fa2a /compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc | |
parent | a2b0ac40cfe37cfacb8648814cc74f6e8d2c0ed3 (diff) | |
download | bcm5719-llvm-a1186b828ffb1b796b067a3d46fcc8e827006a5f.tar.gz bcm5719-llvm-a1186b828ffb1b796b067a3d46fcc8e827006a5f.zip |
[tsan] Handle libdispatch worker threads on OS X
On OS X, GCD worker threads are created without a call to pthread_create. We need to properly register these threads with ThreadCreate and ThreadStart. This patch uses a libpthread API (`pthread_introspection_hook_install`) to get notifications about new threads and about threads that are about to be destroyed.
Differential Revision: http://reviews.llvm.org/D14328
llvm-svn: 252049
Diffstat (limited to 'compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc')
-rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc | 8 |
1 files changed, 6 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 66c78cfdd7c..dcae255f764 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc @@ -55,6 +55,8 @@ void ThreadContext::OnCreated(void *arg) { if (tid == 0) return; OnCreatedArgs *args = static_cast<OnCreatedArgs *>(arg); + if (!args->thr) // GCD workers don't have a parent thread. + return; args->thr->fast_state.IncrementEpoch(); // Can't increment epoch w/o writing to the trace as well. TraceAddEvent(args->thr, args->thr->fast_state, EventTypeMop, 0); @@ -231,8 +233,10 @@ int ThreadCount(ThreadState *thr) { int ThreadCreate(ThreadState *thr, uptr pc, uptr uid, bool detached) { StatInc(thr, StatThreadCreate); OnCreatedArgs args = { thr, pc }; - int tid = ctx->thread_registry->CreateThread(uid, detached, thr->tid, &args); - DPrintf("#%d: ThreadCreate tid=%d uid=%zu\n", thr->tid, tid, uid); + u32 parent_tid = thr ? thr->tid : kInvalidTid; // No parent for GCD workers. + int tid = + ctx->thread_registry->CreateThread(uid, detached, parent_tid, &args); + DPrintf("#%d: ThreadCreate tid=%d uid=%zu\n", parent_tid, tid, uid); StatSet(thr, StatThreadMaxAlive, ctx->thread_registry->GetMaxAliveThreads()); return tid; } |