Mercurial > hg > octave-shane > gnulib-hg
view m4/timer_time.m4 @ 17627:4d899884c95c
m4: fix gl_TIMER_TIME() detection of threads on uClibc
The timer_time.m4 gl_TIMER_TIME function determines which libraries
need to be linked to get access to the timer function, generally -lrt
for Linux systems. On platforms where threads are used, librt
typically uses thread functions from libpthread.
However, the test to determine whether the platform has thread or not
is incorrect: it assumes that if the C library is uClibc, then threads
are not available. This is actually not true: uClibc has configurable
thread support, and when thread support is available, librt calls
libpthread functions.
This is important when static linking is used, because otherwise only
-lrt is used at link time, which fails because librt calls undefined
thread functions. Both -lrt and -lpthread must be passed.
This problem is fixed by making the uClibc thread detection a bit
smarter, thanks to the usage of the __HAS_NO_THREADS__ macro defined
in <bits/uClibc_config.h>, which itself is included by <features.h>.
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
author | Thomas Petazzoni <thomas.petazzoni@free-electrons.com> |
---|---|
date | Sat, 22 Feb 2014 00:41:38 +0100 |
parents | 344018b6e5d7 |
children |
line wrap: on
line source
# timer_time.m4 serial 2 dnl Copyright (C) 2011-2014 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. # Check for timer_settime, and set LIB_TIMER_TIME. AC_DEFUN([gl_TIMER_TIME], [ dnl Based on clock_time.m4. See details there. AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) AC_REQUIRE([gl_THREADLIB]) LIB_TIMER_TIME= AC_SUBST([LIB_TIMER_TIME]) gl_saved_libs=$LIBS AC_SEARCH_LIBS([timer_settime], [rt posix4], [test "$ac_cv_search_timer_settime" = "none required" || LIB_TIMER_TIME=$ac_cv_search_timer_settime]) dnl GLIBC uses threads to emulate posix timers when kernel support dnl is not available (like Linux < 2.6 or when used with kFreeBSD) dnl Now the pthread lib is linked automatically in the normal case, dnl but when linking statically, it needs to be explicitly specified. AC_EGREP_CPP([Thread], [ #include <features.h> #ifdef __GNU_LIBRARY__ #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || (__GLIBC__ > 2)) \ && !(__UCLIBC__ && __HAS_NO_THREADS__) Thread emulation available #endif #endif ], [LIB_TIMER_TIME="$LIB_TIMER_TIME $LIBMULTITHREAD"]) AC_CHECK_FUNCS([timer_settime]) LIBS=$gl_saved_libs ])