From 04e9dd936bfe30c2121997b1f7ef37b0ac7eb52a Mon Sep 17 00:00:00 2001 From: root Date: Thu, 20 Nov 2008 00:35:10 +0000 Subject: *** empty log message *** --- Changes | 3 +++ ev.c | 29 +++++++++++++++++++++++++++++ ev.pod | 36 ++++++++++++++++++++++++++---------- libev.m4 | 14 +++++++++++++- 4 files changed, 71 insertions(+), 11 deletions(-) diff --git a/Changes b/Changes index 647c1d6..0d386a6 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for libev, a high-performance and full-featured event loop. + - new config symbol, EV_USE_CLOCK_SYSCALL, to make libev use + a direct syscall - slower, but no dependency on librt et al. + 3.49 Wed Nov 19 11:26:53 CET 2008 - ev_stat watchers will now use inotify as a mere hint on kernels <2.6.25, or if the filesystem is not in the diff --git a/ev.c b/ev.c index c872176..538f6a5 100644 --- a/ev.c +++ b/ev.c @@ -49,6 +49,18 @@ extern "C" { # include "config.h" # endif +# if HAVE_CLOCK_SYSCALL +# ifndef EV_USE_CLOCK_SYSCALL +# define EV_USE_CLOCK_SYSCALL 1 +# ifndef EV_USE_REALTIME +# define EV_USE_REALTIME 0 +# endif +# ifndef EV_USE_MONOTONIC +# define EV_USE_MONOTONIC 1 +# endif +# endif +# endif + # if HAVE_CLOCK_GETTIME # ifndef EV_USE_MONOTONIC # define EV_USE_MONOTONIC 1 @@ -166,6 +178,14 @@ extern "C" { /* this block tries to deduce configuration from header-defined symbols and defaults */ +#ifndef EV_USE_CLOCK_SYSCALL +# if __linux && __GLIBC__ >= 2 +# define EV_USE_CLOCK_SYSCALL 1 +# else +# define EV_USE_CLOCK_SYSCALL 0 +# endif +#endif + #ifndef EV_USE_MONOTONIC # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 # define EV_USE_MONOTONIC 1 @@ -302,6 +322,15 @@ extern "C" { # include #endif +/* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ +/* which makes programs even slower. might work on other unices, too. */ +#if EV_USE_CLOCK_SYSCALL +# include +# define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) +# undef EV_USE_MONOTONIC +# define EV_USE_MONOTONIC 1 +#endif + #if EV_USE_EVENTFD /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ # include diff --git a/ev.pod b/ev.pod index 48e39da..3803d11 100644 --- a/ev.pod +++ b/ev.pod @@ -3001,6 +3001,9 @@ of the libev API and adds file handle abstractions, asynchronous DNS and more on top of it. It can be found via gem servers. Its homepage is at L. +Roger Pack reports that using the link order C<-lws2_32 -lmsvcrt-ruby-190> +makes rev work even on mingw. + =item D Leandro Lucarella has written a D language binding (F) for libev, to @@ -3186,15 +3189,18 @@ implementations for some libevent functions (such as logging, which is not supported). It will also not define any of the structs usually found in F that are not directly supported by the libev core alone. +In stanbdalone mode, libev will still try to automatically deduce the +configuration, but has to be more conservative. + =item EV_USE_MONOTONIC If defined to be C<1>, libev will try to detect the availability of the -monotonic clock option at both compile time and runtime. Otherwise no use -of the monotonic clock option will be attempted. If you enable this, you -usually have to link against librt or something similar. Enabling it when -the functionality isn't available is safe, though, although you have +monotonic clock option at both compile time and runtime. Otherwise no +use of the monotonic clock option will be attempted. If you enable this, +you usually have to link against librt or something similar. Enabling it +when the functionality isn't available is safe, though, although you have to make sure you link against any libraries where the C -function is hiding in (often F<-lrt>). +function is hiding in (often F<-lrt>). See also C. =item EV_USE_REALTIME @@ -3205,6 +3211,16 @@ be attempted. This effectively replaces C by C and will not normally affect correctness. See the note about libraries in the description of C, though. +=item EV_USE_CLOCK_SYSCALL + +If defined to be C<1>, libev will try to use a direct syscall instead +of calling the system-provided C function. This option +exists because on GNU/Linux, C is in C, but C +unconditionally pulls in C, slowing down single-threaded +programs needlessly. Using a direct syscall is slightly slower, because +no optimised vdso implementation can be used, but avoids the pthread +dependency. Defaults to C<1> on GNU/Linux with glibc 2.x or higher. + =item EV_USE_NANOSLEEP If defined to be C<1>, libev will assume that C is available @@ -3229,11 +3245,11 @@ will not be compiled in. If defined to C<1>, then the select backend will use the system C structure. This is useful if libev doesn't compile due to a missing -C or C definition or it mis-guesses the bitset layout on -exotic systems. This usually limits the range of file descriptors to some -low limit such as 1024 or might have other limitations (winsocket only -allows 64 sockets). The C macro, set before compilation, might -influence the size of the C used. +C or C definition or it mis-guesses the bitset layout +on exotic systems. This usually limits the range of file descriptors to +some low limit such as 1024 or might have other limitations (winsocket +only allows 64 sockets). The C macro, set before compilation, +configures the maximum size of the C. =item EV_SELECT_IS_WINSOCKET diff --git a/libev.m4 b/libev.m4 index 393835e..2ba20eb 100644 --- a/libev.m4 +++ b/libev.m4 @@ -7,7 +7,19 @@ AC_CHECK_HEADERS(sys/inotify.h sys/epoll.h sys/event.h sys/queue.h port.h poll.h AC_CHECK_FUNCS(inotify_init epoll_ctl kqueue port_create poll select eventfd) AC_CHECK_FUNC(clock_gettime, [], [ - if test -z "$LIBEV_M4_AVOID_LIBRT"; then + dnl on linux, try syscall wrapper first + if test $(uname) = Linux; then + AC_MSG_CHECKING(for clock_gettime syscall) + AC_LINK_IFELSE([AC_LANG_PROGRAM( + [#include + #include ], + [struct timespec ts; int status = syscall (SYS_clock_gettime, CLOCK_REALTIME, &ts)])], + [ac_have_clock_syscall=1 + AC_DEFINE(HAVE_CLOCK_SYSCALL, 1, "use syscall interface for clock_gettime") + AC_MSG_RESULT(yes)], + [AC_MSG_RESULT(no)]) + fi + if test -z "$LIBEV_M4_AVOID_LIBRT" && test -z "$ac_have_clock_syscall"; then AC_CHECK_LIB(rt, clock_gettime) unset ac_cv_func_clock_gettime AC_CHECK_FUNCS(clock_gettime) -- cgit v1.2.3