summaryrefslogtreecommitdiff
path: root/configure.ac
diff options
context:
space:
mode:
authorChris Dickens <christopher.a.dickens@gmail.com>2020-01-24 11:51:55 -0800
committerChris Dickens <christopher.a.dickens@gmail.com>2020-02-07 15:56:05 -0800
commita5f6a43342d6bd0da57092ec4e1a6bce30bb2bce (patch)
treefcff5e76bddf71a765bfd66c44c96e6e102019ba /configure.ac
parent9c28ad219b654011783a42ec888ca87dbda704a6 (diff)
downloadlibusb-a5f6a43342d6bd0da57092ec4e1a6bce30bb2bce.tar.gz
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>
Diffstat (limited to 'configure.ac')
-rw-r--r--configure.ac26
1 files changed, 20 insertions, 6 deletions
diff --git a/configure.ac b/configure.ac
index a273688..53a904e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -323,17 +323,31 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
nopointersign_cflags="-Wno-pointer-sign", nopointersign_cflags="")
CFLAGS="${saved_CFLAGS}"
-dnl check for -std=gnu99 compiler support
+dnl check for -std=gnu11 compiler support
saved_CFLAGS="${CFLAGS}"
-CFLAGS="-std=gnu99"
-AC_MSG_CHECKING([whether CC supports -std=gnu99])
+CFLAGS="-std=gnu11"
+AC_MSG_CHECKING([whether CC supports -std=gnu11])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
[AC_MSG_RESULT([yes])
- AM_CFLAGS="${AM_CFLAGS} -std=gnu99"],
- [AC_MSG_RESULT([no])]
-)
+ AM_CFLAGS="${AM_CFLAGS} -std=gnu11"],
+ [AC_MSG_RESULT([no])])
CFLAGS="${saved_CFLAGS}"
+dnl check for _Thread_local compiler support
+if test "x$backend" != xwindows; then
+ saved_CFLAGS="${CFLAGS}"
+ saved_LDFLAGS="${LDFLAGS}"
+ CFLAGS="${CFLAGS} -fPIC"
+ LDFLAGS="${LDFLAGS} -shared"
+ AC_MSG_CHECKING([whether CC supports _Thread_local])
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([], [static _Thread_local int v])],
+ [AC_MSG_RESULT([yes])
+ AC_DEFINE([HAVE_CC_THREAD_LOCAL], [1], [Define to 1 if the compiler supports _Thread_local.])],
+ [AC_MSG_RESULT([no])])
+ CFLAGS="${saved_CFLAGS}"
+ LDFLAGS="${saved_LDFLAGS}"
+fi
+
AM_CFLAGS="${AM_CFLAGS} -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration ${nopointersign_cflags} -Wshadow ${THREAD_CFLAGS} ${VISIBILITY_CFLAGS}"
AC_SUBST(AM_CFLAGS)