This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer] Introduce tid_t as a typedef for OS-provided thread IDs
ClosedPublic

Authored by kubamracek on Apr 6 2017, 10:35 AM.

Details

Summary

We seem to assume that OS-provided thread IDs are either uptr or int, neither of which is true on Darwin. This introduces a tid_t type, which holds a OS-provided thread ID (gettid on Linux, pthread_threadid_np on Darwin, pthread_self on FreeBSD).

Diff Detail

Repository
rL LLVM

Event Timeline

kubamracek created this revision.Apr 6 2017, 10:35 AM
fjricci added inline comments.Apr 6 2017, 10:40 AM
lib/sanitizer_common/sanitizer_stoptheworld.h
21 ↗(On Diff #94391)

Will it be problematic to move SuspendedThreadID from int to uptr on Linux?

kubamracek added inline comments.Apr 6 2017, 10:46 AM
lib/sanitizer_common/sanitizer_stoptheworld.h
21 ↗(On Diff #94391)

I don't see any problems besides using a little bit more space in SuspendedThreadsList below.

I guess we could #ifdef tid_t to int/pid_t on Linux, because that's what gettid returns.

fjricci accepted this revision.Apr 6 2017, 11:09 AM
fjricci added inline comments.
lib/sanitizer_common/sanitizer_stoptheworld.h
21 ↗(On Diff #94391)

I also wasn't sure if we ever used something like -1 for an error condition, but it doesn't appear so. I don't have any objection to uptr, since it seems that most of the code uses that anyway.

This revision is now accepted and ready to land.Apr 6 2017, 11:09 AM
fjricci added inline comments.Apr 12 2017, 9:34 AM
lib/lsan/lsan_common.cc
191 ↗(On Diff #94391)

This line should remain os_id

fjricci added inline comments.Apr 12 2017, 9:49 AM
lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
84 ↗(On Diff #94391)

Hrm, this compiler check fails on my machine (CentOS 7 building for i386)

As an aside we may want pthread_getthreadid_np() (the user-facing thread ID) on FreeBSD instead of pthread_self() (an opaque pointer), as a separate / later change.

Given that D31474 has been approved, it would be great if we could get this merged

Updating the patch and rebasing. Would you mind testing if this patch works on Linux? Thanks!

kubamracek requested review of this revision.Apr 17 2017, 11:03 AM
kubamracek edited edge metadata.
fjricci accepted this revision.Apr 17 2017, 11:16 AM

Builds and passes tests on Linux for me.

This revision is now accepted and ready to land.Apr 17 2017, 11:16 AM
This revision was automatically updated to reflect the committed changes.