1 # Check for a working timer_create(). We need a pretty detailed check
2 # here, because there exist partially-working implementations of
3 # timer_create() in certain versions of Linux (see bug #1933).
5 AC_DEFUN([FP_CHECK_TIMER_CREATE],[
6 AC_CHECK_FUNC([timer_create],[HAVE_timer_create=yes],[HAVE_timer_create=no])
8 if test "$HAVE_timer_create" = "yes"
10 if test "$cross_compiling" = "yes"
12 # We can't test timer_create when we're cross-compiling, so we
13 # optimistiaclly assume that it actually works properly.
14 AC_DEFINE([USE_TIMER_CREATE], 1, [Define to 1 if we can use timer_create(CLOCK_REALTIME,...)])
16 AC_CACHE_CHECK([for a working timer_create(CLOCK_REALTIME)],
17 [fptools_cv_timer_create_works],
20 #if defined(HAVE_STDLIB_H)
24 #if defined(HAVE_SIGNAL_H)
27 #if defined(HAVE_UNISTD_H)
31 static volatile int tock = 0;
32 static void handler(int i)
37 static void timeout(int i)
39 // timer_settime() has been known to hang, so just in case
40 // we install a 1-second timeout (see #2257)
44 int main(int argc, char *argv[])
50 struct sigaction action;
53 ev.sigev_notify = SIGEV_SIGNAL;
54 ev.sigev_signo = SIGVTALRM;
56 action.sa_handler = handler;
58 sigemptyset(&action.sa_mask);
59 if (sigaction(SIGVTALRM, &action, NULL) == -1) {
60 fprintf(stderr,"SIGVTALRM problem\n");
64 action.sa_handler = timeout;
66 sigemptyset(&action.sa_mask);
67 if (sigaction(SIGALRM, &action, NULL) == -1) {
68 fprintf(stderr,"SIGALRM problem\n");
73 if (timer_create(CLOCK_REALTIME, &ev, &timer) != 0) {
74 fprintf(stderr,"No CLOCK_REALTIME timer\n");
80 it.it_value.tv_sec = 0;
81 it.it_value.tv_nsec = 1000000; // 1ms
82 it.it_interval = it.it_value;
83 if (timer_settime(timer, 0, &it, NULL) != 0) {
84 fprintf(stderr,"settime problem\n");
88 // some environments have coarse scheduler/timer granularity of ~10ms and worse
89 usleep(100000); // 100ms
92 fprintf(stderr,"no CLOCK_REALTIME signal\n");
101 [fptools_cv_timer_create_works=yes],
102 [fptools_cv_timer_create_works=no])
104 case $fptools_cv_timer_create_works in
105 yes) AC_DEFINE([USE_TIMER_CREATE], 1,
106 [Define to 1 if we can use timer_create(CLOCK_REALTIME,...)]);;