evdispatch 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. data/History.txt +3 -0
  2. data/Manifest.txt +32 -32
  3. data/ext/revdispatch/extconf.rb +1 -1
  4. data/ext/revdispatch/libdispatch-0.1/Changelog +1 -0
  5. data/ext/revdispatch/libdispatch-0.1/configure +1 -1
  6. data/ext/revdispatch/libdispatch-0.1/configure.ac +1 -1
  7. data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/Changes +24 -0
  8. data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/Makefile.in +172 -234
  9. data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/aclocal.m4 +6449 -6665
  10. data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/autogen.sh +1 -2
  11. data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/config.guess +3 -3
  12. data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/config.h.in +6 -0
  13. data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/config.sub +3 -3
  14. data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/configure +496 -783
  15. data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/configure.ac +1 -1
  16. data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/ev++.h +32 -8
  17. data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/ev.3 +91 -23
  18. data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/ev.c +119 -22
  19. data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/ev.h +59 -37
  20. data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/ev.pod +96 -20
  21. data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/ev_poll.c +17 -14
  22. data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/ev_vars.h +3 -0
  23. data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/ev_wrap.h +2 -0
  24. data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/event.c +1 -1
  25. data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/libev.m4 +2 -2
  26. data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/ltmain.sh +92 -151
  27. data/ext/revdispatch/libdispatch-0.1/src/ev_http.cc +11 -6
  28. data/ext/revdispatch/libdispatch-0.1/test/stress_test.cc +1 -1
  29. data/ext/revdispatch/server.rb +11 -23
  30. data/ext/revdispatch/stest.rb +3 -3
  31. data/lib/evdispatch/version.rb +1 -1
  32. data/website/index.html +1 -1
  33. metadata +35 -35
  34. /data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/LICENSE +0 -0
  35. /data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/Makefile.am +0 -0
  36. /data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/README +0 -0
  37. /data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/ev_epoll.c +0 -0
  38. /data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/ev_kqueue.c +0 -0
  39. /data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/ev_port.c +0 -0
  40. /data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/ev_select.c +0 -0
  41. /data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/ev_win32.c +0 -0
  42. /data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/event.h +0 -0
  43. /data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/install-sh +0 -0
  44. /data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/missing +0 -0
  45. /data/ext/revdispatch/libdispatch-0.1/{libev-3.2 → libev-3.31}/mkinstalldirs +0 -0
@@ -1,7 +1,7 @@
1
1
  AC_INIT
2
2
  AC_CONFIG_SRCDIR([ev_epoll.c])
3
3
 
4
- AM_INIT_AUTOMAKE(libev,3.2)
4
+ AM_INIT_AUTOMAKE(libev,3.31)
5
5
  AC_CONFIG_HEADERS([config.h])
6
6
  AM_MAINTAINER_MODE
7
7
 
@@ -72,6 +72,7 @@ namespace ev {
72
72
  CHECK = EV_CHECK,
73
73
  PREPARE = EV_PREPARE,
74
74
  FORK = EV_FORK,
75
+ ASYNC = EV_ASYNC,
75
76
  EMBED = EV_EMBED,
76
77
  ERROR = EV_ERROR,
77
78
  };
@@ -563,13 +564,13 @@ namespace ev {
563
564
 
564
565
  #if EV_MULTIPLICITY
565
566
  #define EV_CONSTRUCT(cppstem,cstem) \
566
- (EV_PX = get_default_loop ()) throw () \
567
+ (EV_PX = get_default_loop ()) throw () \
567
568
  : base<ev_ ## cstem, cppstem> (EV_A) \
568
569
  { \
569
570
  }
570
571
  #else
571
572
  #define EV_CONSTRUCT(cppstem,cstem) \
572
- () throw () \
573
+ () throw () \
573
574
  { \
574
575
  }
575
576
  #endif
@@ -580,19 +581,19 @@ namespace ev {
580
581
  \
581
582
  struct cppstem : base<ev_ ## cstem, cppstem> \
582
583
  { \
583
- void start () throw () \
584
+ void start () throw () \
584
585
  { \
585
586
  ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \
586
587
  } \
587
588
  \
588
- void stop () throw () \
589
+ void stop () throw () \
589
590
  { \
590
591
  ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \
591
592
  } \
592
593
  \
593
594
  cppstem EV_CONSTRUCT(cppstem,cstem) \
594
595
  \
595
- ~cppstem () throw () \
596
+ ~cppstem () throw () \
596
597
  { \
597
598
  stop (); \
598
599
  } \
@@ -603,7 +604,7 @@ namespace ev {
603
604
  \
604
605
  cppstem (const cppstem &o); \
605
606
  \
606
- cppstem & operator =(const cppstem &o); \
607
+ cppstem &operator =(const cppstem &o); \
607
608
  \
608
609
  public:
609
610
 
@@ -748,10 +749,17 @@ namespace ev {
748
749
 
749
750
  #if EV_EMBED_ENABLE
750
751
  EV_BEGIN_WATCHER (embed, embed)
751
- void start (struct ev_loop *embedded_loop) throw ()
752
+ void set (struct ev_loop *embedded_loop) throw ()
752
753
  {
753
- stop ();
754
+ int active = is_active ();
755
+ if (active) stop ();
754
756
  ev_embed_set (static_cast<ev_embed *>(this), embedded_loop);
757
+ if (active) start ();
758
+ }
759
+
760
+ void start (struct ev_loop *embedded_loop) throw ()
761
+ {
762
+ set (embedded_loop);
755
763
  start ();
756
764
  }
757
765
 
@@ -768,6 +776,22 @@ namespace ev {
768
776
  EV_END_WATCHER (fork, fork)
769
777
  #endif
770
778
 
779
+ #if EV_ASYNC_ENABLE
780
+ EV_BEGIN_WATCHER (async, async)
781
+ void set () throw () { }
782
+
783
+ void send () throw ()
784
+ {
785
+ ev_async_send (EV_A_ static_cast<ev_async *>(this));
786
+ }
787
+
788
+ bool async_pending () throw ()
789
+ {
790
+ return ev_async_pending (static_cast<ev_async *>(this));
791
+ }
792
+ EV_END_WATCHER (async, async)
793
+ #endif
794
+
771
795
  #undef EV_PX
772
796
  #undef EV_PX_
773
797
  #undef EV_CONSTRUCT
@@ -132,7 +132,7 @@
132
132
  .\" ========================================================================
133
133
  .\"
134
134
  .IX Title "EV 1"
135
- .TH EV 1 "2008-04-02" "perl v5.10.0" "User Contributed Perl Documentation"
135
+ .TH EV 1 "2008-04-11" "perl v5.10.0" "User Contributed Perl Documentation"
136
136
  .\" For nroff, turn off justification. Always turn off hyphenation; it makes
137
137
  .\" way too many mistakes in technical documents.
138
138
  .if n .ad l
@@ -330,18 +330,21 @@ See the description of \f(CW\*(C`ev_embed\*(C'\fR watchers for more info.
330
330
  .IP "ev_set_allocator (void *(*cb)(void *ptr, long size))" 4
331
331
  .IX Item "ev_set_allocator (void *(*cb)(void *ptr, long size))"
332
332
  Sets the allocation function to use (the prototype is similar \- the
333
- semantics is identical \- to the realloc C function). It is used to
334
- allocate and free memory (no surprises here). If it returns zero when
335
- memory needs to be allocated, the library might abort or take some
336
- potentially destructive action. The default is your system realloc
337
- function.
333
+ semantics are identical to the \f(CW\*(C`realloc\*(C'\fR C89/SuS/POSIX function). It is
334
+ used to allocate and free memory (no surprises here). If it returns zero
335
+ when memory needs to be allocated (\f(CW\*(C`size != 0\*(C'\fR), the library might abort
336
+ or take some potentially destructive action.
337
+ .Sp
338
+ Since some systems (at least OpenBSD and Darwin) fail to implement
339
+ correct \f(CW\*(C`realloc\*(C'\fR semantics, libev will use a wrapper around the system
340
+ \&\f(CW\*(C`realloc\*(C'\fR and \f(CW\*(C`free\*(C'\fR functions by default.
338
341
  .Sp
339
342
  You could override this function in high-availability programs to, say,
340
343
  free some memory if it cannot allocate memory, to use a special allocator,
341
344
  or even to sleep a while and retry until some memory is available.
342
345
  .Sp
343
346
  Example: Replace the libev allocator with one that waits a bit and then
344
- retries).
347
+ retries (example requires a standards-compliant \f(CW\*(C`realloc\*(C'\fR).
345
348
  .Sp
346
349
  .Vb 6
347
350
  \& static void *
@@ -389,13 +392,6 @@ Example: This is basically the same thing that libev does internally, too.
389
392
  An event loop is described by a \f(CW\*(C`struct ev_loop *\*(C'\fR. The library knows two
390
393
  types of such loops, the \fIdefault\fR loop, which supports signals and child
391
394
  events, and dynamically created loops which do not.
392
- .PP
393
- If you use threads, a common model is to run the default event loop
394
- in your main thread (or in a separate thread) and for each thread you
395
- create, you also create another event loop. Libev itself does no locking
396
- whatsoever, so if you mix calls to the same event loop in different
397
- threads, make sure you lock (this is usually a bad idea, though, even if
398
- done correctly, because it's hideous and inefficient).
399
395
  .IP "struct ev_loop *ev_default_loop (unsigned int flags)" 4
400
396
  .IX Item "struct ev_loop *ev_default_loop (unsigned int flags)"
401
397
  This will initialise the default event loop if it hasn't been initialised
@@ -488,7 +484,7 @@ but it scales phenomenally better. While poll and select usually scale
488
484
  like O(total_fds) where n is the total number of fds (or the highest fd),
489
485
  epoll scales either O(1) or O(active_fds). The epoll design has a number
490
486
  of shortcomings, such as silently dropping events in some hard-to-detect
491
- cases and rewiring a syscall per fd change, no fork support and bad
487
+ cases and requiring a syscall per fd change, no fork support and bad
492
488
  support for dup.
493
489
  .Sp
494
490
  While stopping, setting and starting an I/O watcher in the same iteration
@@ -2498,6 +2494,9 @@ Priorities are not currently supported. Initialising priorities
2498
2494
  will fail and all watchers will have the same priority, even though there
2499
2495
  is an ev_pri field.
2500
2496
  .IP "\(bu" 4
2497
+ In libevent, the last base created gets the signals, in libev, the
2498
+ first base created (== the default loop) gets the signals.
2499
+ .IP "\(bu" 4
2501
2500
  Other members are not supported.
2502
2501
  .IP "\(bu" 4
2503
2502
  The libev emulation is \fInot\fR \s-1ABI\s0 compatible to libevent, you need
@@ -2735,6 +2734,16 @@ suitable for use with \f(CW\*(C`EV_A\*(C'\fR.
2735
2734
  .IX Item "EV_DEFAULT, EV_DEFAULT_"
2736
2735
  Similar to the other two macros, this gives you the value of the default
2737
2736
  loop, if multiple loops are supported (\*(L"ev loop default\*(R").
2737
+ .ie n .IP """EV_DEFAULT_UC""\fR, \f(CW""EV_DEFAULT_UC_""" 4
2738
+ .el .IP "\f(CWEV_DEFAULT_UC\fR, \f(CWEV_DEFAULT_UC_\fR" 4
2739
+ .IX Item "EV_DEFAULT_UC, EV_DEFAULT_UC_"
2740
+ Usage identical to \f(CW\*(C`EV_DEFAULT\*(C'\fR and \f(CW\*(C`EV_DEFAULT_\*(C'\fR, but requires that the
2741
+ default loop has been initialised (\f(CW\*(C`UC\*(C'\fR == unchecked). Their behaviour
2742
+ is undefined when the default loop has not been initialised by a previous
2743
+ execution of \f(CW\*(C`EV_DEFAULT\*(C'\fR, \f(CW\*(C`EV_DEFAULT_\*(C'\fR or \f(CW\*(C`ev_default_init (...)\*(C'\fR.
2744
+ .Sp
2745
+ It is often prudent to use \f(CW\*(C`EV_DEFAULT\*(C'\fR when initialising the first
2746
+ watcher in a function but use \f(CW\*(C`EV_DEFAULT_UC\*(C'\fR afterwards.
2738
2747
  .PP
2739
2748
  Example: Declare and initialise a check watcher, utilising the above
2740
2749
  macros so it will work regardless of whether multiple loops are supported
@@ -2854,9 +2863,9 @@ For this of course you need the m4 file:
2854
2863
  .Ve
2855
2864
  .Sh "\s-1PREPROCESSOR\s0 \s-1SYMBOLS/MACROS\s0"
2856
2865
  .IX Subsection "PREPROCESSOR SYMBOLS/MACROS"
2857
- Libev can be configured via a variety of preprocessor symbols you have to define
2858
- before including any of its files. The default is not to build for multiplicity
2859
- and only include the select backend.
2866
+ Libev can be configured via a variety of preprocessor symbols you have to
2867
+ define before including any of its files. The default in the absense of
2868
+ autoconf is noted for every option.
2860
2869
  .IP "\s-1EV_STANDALONE\s0" 4
2861
2870
  .IX Item "EV_STANDALONE"
2862
2871
  Must always be \f(CW1\fR if you do not use autoconf configuration, which
@@ -2885,6 +2894,13 @@ note about libraries in the description of \f(CW\*(C`EV_USE_MONOTONIC\*(C'\fR, t
2885
2894
  .IX Item "EV_USE_NANOSLEEP"
2886
2895
  If defined to be \f(CW1\fR, libev will assume that \f(CW\*(C`nanosleep ()\*(C'\fR is available
2887
2896
  and will use it for delays. Otherwise it will use \f(CW\*(C`select ()\*(C'\fR.
2897
+ .IP "\s-1EV_USE_EVENTFD\s0" 4
2898
+ .IX Item "EV_USE_EVENTFD"
2899
+ If defined to be \f(CW1\fR, then libev will assume that \f(CW\*(C`eventfd ()\*(C'\fR is
2900
+ available and will probe for kernel support at runtime. This will improve
2901
+ \&\f(CW\*(C`ev_signal\*(C'\fR and \f(CW\*(C`ev_async\*(C'\fR performance and reduce resource consumption.
2902
+ If undefined, it will be enabled if the headers indicate GNU/Linux + Glibc
2903
+ 2.7 or newer, otherwise disabled.
2888
2904
  .IP "\s-1EV_USE_SELECT\s0" 4
2889
2905
  .IX Item "EV_USE_SELECT"
2890
2906
  If undefined or defined to be \f(CW1\fR, libev will compile in support for the
@@ -2925,8 +2941,9 @@ takes precedence over select.
2925
2941
  .IX Item "EV_USE_EPOLL"
2926
2942
  If defined to be \f(CW1\fR, libev will compile in support for the Linux
2927
2943
  \&\f(CW\*(C`epoll\*(C'\fR(7) backend. Its availability will be detected at runtime,
2928
- otherwise another method will be used as fallback. This is the
2929
- preferred backend for GNU/Linux systems.
2944
+ otherwise another method will be used as fallback. This is the preferred
2945
+ backend for GNU/Linux systems. If undefined, it will be enabled if the
2946
+ headers indicate GNU/Linux + Glibc 2.4 or newer, otherwise disabled.
2930
2947
  .IP "\s-1EV_USE_KQUEUE\s0" 4
2931
2948
  .IX Item "EV_USE_KQUEUE"
2932
2949
  If defined to be \f(CW1\fR, libev will compile in support for the \s-1BSD\s0 style
@@ -2951,7 +2968,8 @@ reserved for future expansion, works like the \s-1USE\s0 symbols above.
2951
2968
  .IX Item "EV_USE_INOTIFY"
2952
2969
  If defined to be \f(CW1\fR, libev will compile in support for the Linux inotify
2953
2970
  interface to speed up \f(CW\*(C`ev_stat\*(C'\fR watchers. Its actual availability will
2954
- be detected at runtime.
2971
+ be detected at runtime. If undefined, it will be enabled if the headers
2972
+ indicate GNU/Linux + Glibc 2.4 or newer, otherwise disabled.
2955
2973
  .IP "\s-1EV_ATOMIC_T\s0" 4
2956
2974
  .IX Item "EV_ATOMIC_T"
2957
2975
  Libev requires an integer type (suitable for storing \f(CW0\fR or \f(CW1\fR) whose
@@ -3142,6 +3160,56 @@ And a \fIev_cpp.C\fR implementation file that contains libev proper and is compi
3142
3160
  \& #include "ev_cpp.h"
3143
3161
  \& #include "ev.c"
3144
3162
  .Ve
3163
+ .SH "THREADS AND COROUTINES"
3164
+ .IX Header "THREADS AND COROUTINES"
3165
+ .Sh "\s-1THREADS\s0"
3166
+ .IX Subsection "THREADS"
3167
+ Libev itself is completely threadsafe, but it uses no locking. This
3168
+ means that you can use as many loops as you want in parallel, as long as
3169
+ only one thread ever calls into one libev function with the same loop
3170
+ parameter.
3171
+ .PP
3172
+ Or put differently: calls with different loop parameters can be done in
3173
+ parallel from multiple threads, calls with the same loop parameter must be
3174
+ done serially (but can be done from different threads, as long as only one
3175
+ thread ever is inside a call at any point in time, e.g. by using a mutex
3176
+ per loop).
3177
+ .PP
3178
+ If you want to know which design is best for your problem, then I cannot
3179
+ help you but by giving some generic advice:
3180
+ .IP "\(bu" 4
3181
+ most applications have a main thread: use the default libev loop
3182
+ in that thread, or create a seperate thread running only the default loop.
3183
+ .Sp
3184
+ This helps integrating other libraries or software modules that use libev
3185
+ themselves and don't care/know about threading.
3186
+ .IP "\(bu" 4
3187
+ one loop per thread is usually a good model.
3188
+ .Sp
3189
+ Doing this is almost never wrong, sometimes a better-performance model
3190
+ exists, but it is always a good start.
3191
+ .IP "\(bu" 4
3192
+ other models exist, such as the leader/follower pattern, where one
3193
+ loop is handed through multiple threads in a kind of round-robbin fashion.
3194
+ .Sp
3195
+ Chosing a model is hard \- look around, learn, know that usually you cna do
3196
+ better than you currently do :\-)
3197
+ .IP "\(bu" 4
3198
+ often you need to talk to some other thread which blocks in the
3199
+ event loop \- \f(CW\*(C`ev_async\*(C'\fR watchers can be used to wake them up from other
3200
+ threads safely (or from signal contexts...).
3201
+ .Sh "\s-1COROUTINES\s0"
3202
+ .IX Subsection "COROUTINES"
3203
+ Libev is much more accomodating to coroutines (\*(L"cooperative threads\*(R"):
3204
+ libev fully supports nesting calls to it's functions from different
3205
+ coroutines (e.g. you can call \f(CW\*(C`ev_loop\*(C'\fR on the same loop from two
3206
+ different coroutines and switch freely between both coroutines running the
3207
+ loop, as long as you don't confuse yourself). The only exception is that
3208
+ you must not do this from \f(CW\*(C`ev_periodic\*(C'\fR reschedule callbacks.
3209
+ .PP
3210
+ Care has been invested into making sure that libev does not keep local
3211
+ state inside \f(CW\*(C`ev_loop\*(C'\fR, and other calls do not usually allow coroutine
3212
+ switches.
3145
3213
  .SH "COMPLEXITIES"
3146
3214
  .IX Header "COMPLEXITIES"
3147
3215
  In this section the complexities of (many of) the algorithms used inside
@@ -3271,6 +3339,6 @@ Marc Lehmann <libev@schmorp.de>.
3271
3339
  .SH "POD ERRORS"
3272
3340
  .IX Header "POD ERRORS"
3273
3341
  Hey! \fBThe above document had some coding errors, which are explained below:\fR
3274
- .IP "Around line 2996:" 4
3275
- .IX Item "Around line 2996:"
3342
+ .IP "Around line 3015:" 4
3343
+ .IX Item "Around line 3015:"
3276
3344
  You forgot a '=back' before '=head2'
@@ -41,6 +41,7 @@
41
41
  extern "C" {
42
42
  #endif
43
43
 
44
+ /* this big block deduces configuration from config.h */
44
45
  #ifndef EV_STANDALONE
45
46
  # ifdef EV_CONFIG_H
46
47
  # include EV_CONFIG_H
@@ -120,6 +121,14 @@ extern "C" {
120
121
  # endif
121
122
  # endif
122
123
 
124
+ # ifndef EV_USE_EVENTFD
125
+ # if HAVE_EVENTFD
126
+ # define EV_USE_EVENTFD 1
127
+ # else
128
+ # define EV_USE_EVENTFD 0
129
+ # endif
130
+ # endif
131
+
123
132
  #endif
124
133
 
125
134
  #include <math.h>
@@ -154,7 +163,7 @@ extern "C" {
154
163
  # endif
155
164
  #endif
156
165
 
157
- /**/
166
+ /* this block tries to deduce configuration from header-defined symbols and defaults */
158
167
 
159
168
  #ifndef EV_USE_MONOTONIC
160
169
  # define EV_USE_MONOTONIC 0
@@ -181,7 +190,11 @@ extern "C" {
181
190
  #endif
182
191
 
183
192
  #ifndef EV_USE_EPOLL
184
- # define EV_USE_EPOLL 0
193
+ # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4))
194
+ # define EV_USE_EPOLL 1
195
+ # else
196
+ # define EV_USE_EPOLL 0
197
+ # endif
185
198
  #endif
186
199
 
187
200
  #ifndef EV_USE_KQUEUE
@@ -193,7 +206,11 @@ extern "C" {
193
206
  #endif
194
207
 
195
208
  #ifndef EV_USE_INOTIFY
196
- # define EV_USE_INOTIFY 0
209
+ # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4))
210
+ # define EV_USE_INOTIFY 1
211
+ # else
212
+ # define EV_USE_INOTIFY 0
213
+ # endif
197
214
  #endif
198
215
 
199
216
  #ifndef EV_PID_HASHSIZE
@@ -212,7 +229,15 @@ extern "C" {
212
229
  # endif
213
230
  #endif
214
231
 
215
- /**/
232
+ #ifndef EV_USE_EVENTFD
233
+ # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7))
234
+ # define EV_USE_EVENTFD 1
235
+ # else
236
+ # define EV_USE_EVENTFD 0
237
+ # endif
238
+ #endif
239
+
240
+ /* this block fixes any misconfiguration where we know we run into trouble otherwise */
216
241
 
217
242
  #ifndef CLOCK_MONOTONIC
218
243
  # undef EV_USE_MONOTONIC
@@ -243,6 +268,18 @@ extern "C" {
243
268
  # include <winsock.h>
244
269
  #endif
245
270
 
271
+ #if EV_USE_EVENTFD
272
+ /* our minimum requirement is glibc 2.7 which has the stub, but not the header */
273
+ # include <stdint.h>
274
+ # ifdef __cplusplus
275
+ extern "C" {
276
+ # endif
277
+ int eventfd (unsigned int initval, int flags);
278
+ # ifdef __cplusplus
279
+ }
280
+ # endif
281
+ #endif
282
+
246
283
  /**/
247
284
 
248
285
  /*
@@ -265,7 +302,7 @@ extern "C" {
265
302
  #else
266
303
  # define expect(expr,value) (expr)
267
304
  # define noinline
268
- # if __STDC_VERSION__ < 199901L
305
+ # if __STDC_VERSION__ < 199901L && __GNUC__ < 2
269
306
  # define inline
270
307
  # endif
271
308
  #endif
@@ -325,7 +362,22 @@ syserr (const char *msg)
325
362
  }
326
363
  }
327
364
 
328
- static void *(*alloc)(void *ptr, long size);
365
+ static void *
366
+ ev_realloc_emul (void *ptr, long size)
367
+ {
368
+ /* some systems, notably openbsd and darwin, fail to properly
369
+ * implement realloc (x, 0) (as required by both ansi c-98 and
370
+ * the single unix specification, so work around them here.
371
+ */
372
+
373
+ if (size)
374
+ return realloc (ptr, size);
375
+
376
+ free (ptr);
377
+ return 0;
378
+ }
379
+
380
+ static void *(*alloc)(void *ptr, long size) = ev_realloc_emul;
329
381
 
330
382
  void
331
383
  ev_set_allocator (void *(*cb)(void *ptr, long size))
@@ -336,7 +388,7 @@ ev_set_allocator (void *(*cb)(void *ptr, long size))
336
388
  inline_speed void *
337
389
  ev_realloc (void *ptr, long size)
338
390
  {
339
- ptr = alloc ? alloc (ptr, size) : realloc (ptr, size);
391
+ ptr = alloc (ptr, size);
340
392
 
341
393
  if (!ptr && size)
342
394
  {
@@ -804,13 +856,24 @@ evpipe_init (EV_P)
804
856
  {
805
857
  if (!ev_is_active (&pipeev))
806
858
  {
807
- while (pipe (evpipe))
808
- syserr ("(libev) error creating signal/async pipe");
859
+ #if EV_USE_EVENTFD
860
+ if ((evfd = eventfd (0, 0)) >= 0)
861
+ {
862
+ evpipe [0] = -1;
863
+ fd_intern (evfd);
864
+ ev_io_set (&pipeev, evfd, EV_READ);
865
+ }
866
+ else
867
+ #endif
868
+ {
869
+ while (pipe (evpipe))
870
+ syserr ("(libev) error creating signal/async pipe");
809
871
 
810
- fd_intern (evpipe [0]);
811
- fd_intern (evpipe [1]);
872
+ fd_intern (evpipe [0]);
873
+ fd_intern (evpipe [1]);
874
+ ev_io_set (&pipeev, evpipe [0], EV_READ);
875
+ }
812
876
 
813
- ev_io_set (&pipeev, evpipe [0], EV_READ);
814
877
  ev_io_start (EV_A_ &pipeev);
815
878
  ev_unref (EV_A); /* watcher should not keep loop alive */
816
879
  }
@@ -824,7 +887,16 @@ evpipe_write (EV_P_ EV_ATOMIC_T *flag)
824
887
  int old_errno = errno; /* save errno because write might clobber it */
825
888
 
826
889
  *flag = 1;
827
- write (evpipe [1], &old_errno, 1);
890
+
891
+ #if EV_USE_EVENTFD
892
+ if (evfd >= 0)
893
+ {
894
+ uint64_t counter = 1;
895
+ write (evfd, &counter, sizeof (uint64_t));
896
+ }
897
+ else
898
+ #endif
899
+ write (evpipe [1], &old_errno, 1);
828
900
 
829
901
  errno = old_errno;
830
902
  }
@@ -833,10 +905,18 @@ evpipe_write (EV_P_ EV_ATOMIC_T *flag)
833
905
  static void
834
906
  pipecb (EV_P_ ev_io *iow, int revents)
835
907
  {
836
- {
837
- int dummy;
838
- read (evpipe [0], &dummy, 1);
839
- }
908
+ #if EV_USE_EVENTFD
909
+ if (evfd >= 0)
910
+ {
911
+ uint64_t counter = 1;
912
+ read (evfd, &counter, sizeof (uint64_t));
913
+ }
914
+ else
915
+ #endif
916
+ {
917
+ char dummy;
918
+ read (evpipe [0], &dummy, 1);
919
+ }
840
920
 
841
921
  if (gotsig && ev_is_default_loop (EV_A))
842
922
  {
@@ -1107,7 +1187,7 @@ loop_init (EV_P_ unsigned int flags)
1107
1187
  && getenv ("LIBEV_FLAGS"))
1108
1188
  flags = atoi (getenv ("LIBEV_FLAGS"));
1109
1189
 
1110
- if (!(flags & 0x0000ffffUL))
1190
+ if (!(flags & 0x0000ffffU))
1111
1191
  flags |= ev_recommended_backends ();
1112
1192
 
1113
1193
  #if EV_USE_PORT
@@ -1141,8 +1221,16 @@ loop_destroy (EV_P)
1141
1221
  ev_ref (EV_A); /* signal watcher */
1142
1222
  ev_io_stop (EV_A_ &pipeev);
1143
1223
 
1144
- close (evpipe [0]); evpipe [0] = 0;
1145
- close (evpipe [1]); evpipe [1] = 0;
1224
+ #if EV_USE_EVENTFD
1225
+ if (evfd >= 0)
1226
+ close (evfd);
1227
+ #endif
1228
+
1229
+ if (evpipe [0] >= 0)
1230
+ {
1231
+ close (evpipe [0]);
1232
+ close (evpipe [1]);
1233
+ }
1146
1234
  }
1147
1235
 
1148
1236
  #if EV_USE_INOTIFY
@@ -1226,8 +1314,17 @@ loop_fork (EV_P)
1226
1314
 
1227
1315
  ev_ref (EV_A);
1228
1316
  ev_io_stop (EV_A_ &pipeev);
1229
- close (evpipe [0]);
1230
- close (evpipe [1]);
1317
+
1318
+ #if EV_USE_EVENTFD
1319
+ if (evfd >= 0)
1320
+ close (evfd);
1321
+ #endif
1322
+
1323
+ if (evpipe [0] >= 0)
1324
+ {
1325
+ close (evpipe [0]);
1326
+ close (evpipe [1]);
1327
+ }
1231
1328
 
1232
1329
  evpipe_init (EV_A);
1233
1330
  /* now iterate over everything, in case we missed something */