summaryrefslogtreecommitdiff
path: root/etr_short_sleep.m4
blob: a46790e345be0d21adf12a7fb0ac90c9b4c1af96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# ===========================================================================
#            http://autoconf-archive.cryp.to/etr_short_sleep.html
# ===========================================================================
#
# SYNOPSIS
#
#   ETR_SHORT_SLEEP
#
# DESCRIPTION
#
#   This macro searches for a "sleep" function that has 1/1000 of a second
#   accuracy. On some systems, this is known as nap() and on others usleep()
#   / 1000. There are probably other functions like this defined in other
#   system libraries, but we don't know how to search for them yet.
#   Contributions joyously accepted. :)
#
# LICENSE
#
#   Copyright (c) 2008 Warren Young <warren@etr-usa.com>
#
#   Copying and distribution of this file, with or without modification, are
#   permitted in any medium without royalty provided the copyright notice
#   and this notice are preserved.

AC_DEFUN([ETR_SHORT_SLEEP],
[
        AC_MSG_CHECKING([for nap() in libc])
        AC_TRY_LINK([ extern "C" long nap(long ms); ], [ nap(42); ],
                [
                        etr_ss_found=yes
                        etr_ss_factor=1
                        AC_DEFINE(HAVE_NAP,1,
                                [Define to use the nap() system call for short sleeps])
                        AC_MSG_RESULT(yes)
                ],
                [
                        AC_MSG_RESULT(no)
                        etr_ss_found=no
                ])

        if test x"$etr_ss_found" = "xno"
        then
                AC_MSG_CHECKING([for usleep()])
                AC_TRY_LINK([ #include <unistd.h> ], [ usleep(42); ],
                        [
                                etr_ss_found=yes
                                etr_ss_factor=1000
                                AC_DEFINE(HAVE_USLEEP,1,
                                        [Define to use the usleep() system call for short sleeps])
                                AC_MSG_RESULT(yes)
                        ],
                        [
                                AC_MSG_RESULT(no)
                                etr_ss_found=no
                        ])
        fi

        if test x"$etr_ss_found" = "xno"
        then
                save_LIBS=$LIBS
                LIBS="$LIBS -lx"
                AC_MSG_CHECKING([for nap() in libx])
                AC_TRY_LINK([ extern "C" long nap(long ms); ], [ nap(42); ],
                        [
                                etr_ss_found=yes
                                etr_ss_factor=1
                                AC_DEFINE(HAVE_NAP,1,
                                        [Define to use the nap() system call for short sleeps])
                                AC_MSG_RESULT(yes)
                        ],
                        [
                                AC_MSG_RESULT(no)
                                etr_ss_found=no
                        ])

                LIBS=$save_LIBS
                ETR_SS_LIB=-lx
                AC_SUBST(ETR_SS_LIB)
        fi

        if test x"$etr_ss_found" = "xyes"
        then
                AC_DEFINE_UNQUOTED(SHORT_SLEEP_FACTOR, $etr_ss_factor,
                        [Multiply milliseconds by this to get the argument for the short sleep system call])
        else
                AC_MSG_ERROR([Could not find a "short sleep" system call.])
        fi
])dnl ETR_SHORT_SLEEP