threads_posix: Use thread-local storage to cache thread ID
authorChris Dickens <christopher.a.dickens@gmail.com>
Fri, 24 Jan 2020 19:51:55 +0000 (11:51 -0800)
committerChris Dickens <christopher.a.dickens@gmail.com>
Fri, 7 Feb 2020 23:56:05 +0000 (15:56 -0800)
commita5f6a43342d6bd0da57092ec4e1a6bce30bb2bce
treefcff5e76bddf71a765bfd66c44c96e6e102019ba
parent9c28ad219b654011783a42ec888ca87dbda704a6
threads_posix: Use thread-local storage to cache thread ID

Trying to capture debug logs that reproduce a problem can be tricky.
Turning up the debug level will automatically make the program a bit
slower. This alone cane make timing-sensitive bugs "disappear" when
capturing logs. One of the hot paths for debug messages is fetching the
thread ID, which is immeasurably helpful in understanding thread
interactions within the library. Unfortunately most implementations
require a system call to fetch the executing thread's ID, which isn't
exactly going to help in the way of execution time.

Add a check for thread-local storage support when configuring the
library to build. If the toolchain provides this support, only one
system call will be required per thread. This check is only done for
non-Windows systems because thread-local storage is inefficiently
implemented on MinGW.

Closes #682

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
configure.ac
libusb/os/threads_posix.c
libusb/version_nano.h