0
+/* this big block deduces configuration from config.h */
0
@@ -120,6 +121,14 @@ extern "C" {
0
+# ifndef EV_USE_EVENTFD
0
+# define EV_USE_EVENTFD 1
0
+# define EV_USE_EVENTFD 0
0
@@ -154,7 +163,7 @@ extern "C" {
0
+/*
this block tries to deduce configuration from header-defined symbols and defaults */
0
#ifndef EV_USE_MONOTONIC
0
# define EV_USE_MONOTONIC 0
0
@@ -181,7 +190,11 @@ extern "C" {
0
-# define EV_USE_EPOLL 0
0
+# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4))
0
+# define EV_USE_EPOLL 1
0
+# define EV_USE_EPOLL 0
0
@@ -193,7 +206,11 @@ extern "C" {
0
-# define EV_USE_INOTIFY 0
0
+# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4))
0
+# define EV_USE_INOTIFY 1
0
+# define EV_USE_INOTIFY 0
0
#ifndef EV_PID_HASHSIZE
0
@@ -212,7 +229,33 @@ extern "C" {
0
+# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7))
0
+# define EV_USE_EVENTFD 1
0
+# define EV_USE_EVENTFD 0
0
+# define EV_USE_4HEAP 1
0
+# define EV_HEAP_CACHE_AT 1
0
+# define EV_VERIFY !EV_MINIMAL
0
+# define EV_USE_4HEAP !EV_MINIMAL
0
+#ifndef EV_HEAP_CACHE_AT
0
+# define EV_HEAP_CACHE_AT !EV_MINIMAL
0
+/* this block fixes any misconfiguration where we know we run into trouble otherwise */
0
#ifndef CLOCK_MONOTONIC
0
# undef EV_USE_MONOTONIC
0
@@ -243,8 +286,26 @@ extern "C" {
0
+/* our minimum requirement is glibc 2.7 which has the stub, but not the header */
0
+int eventfd (unsigned int initval, int flags);
0
+# define EV_FREQUENT_CHECK ev_loop_verify (EV_A)
0
+# define EV_FREQUENT_CHECK do { } while (0)
0
* This is used to avoid floating point rounding problems.
0
* It is added to ev_rt_now when scheduling periodics
0
@@ -265,7 +326,7 @@ extern "C" {
0
# define expect(expr,value) (expr)
0
-# if __STDC_VERSION__ < 199901L
0
+# if __STDC_VERSION__ < 199901L
&& __GNUC__ < 20
@@ -290,6 +351,9 @@ typedef ev_watcher *W;
0
typedef ev_watcher_list *WL;
0
typedef ev_watcher_time *WT;
0
+#define ev_active(w) ((W)(w))->active
0
+#define ev_at(w) ((WT)(w))->at
0
/* sig_atomic_t is used to avoid per-thread variables or locking but still */
0
/* giving it a reasonably high chance of working on typical architetcures */
0
@@ -325,7 +389,22 @@ syserr (const char *msg)
0
-static void *(*alloc)(void *ptr, long size);
0
+ev_realloc_emul (void *ptr, long size)
0
+ /* some systems, notably openbsd and darwin, fail to properly
0
+ * implement realloc (x, 0) (as required by both ansi c-98 and
0
+ * the single unix specification, so work around them here.
0
+ return realloc (ptr, size);
0
+static void *(*alloc)(void *ptr, long size) = ev_realloc_emul;
0
ev_set_allocator (void *(*cb)(void *ptr, long size))
0
@@ -336,7 +415,7 @@ ev_set_allocator (void *(*cb)(void *ptr, long size))
0
ev_realloc (void *ptr, long size)
0
- ptr = alloc
? alloc (ptr, size) : realloc (ptr, size);
0
+ ptr = alloc
(ptr, size);
0
@@ -369,12 +448,31 @@ typedef struct
0
+/* hash table entry per inotify-id */
0
+ #define ANHE_w(he) (he).w /* access watcher, read-write */
0
+ #define ANHE_at(he) (he).at /* access cached at, read-only */
0
+ #define ANHE_at_cache(he) (he).at = (he).w->at /* update at from watcher */
0
+ #define ANHE_w(he) (he)
0
+ #define ANHE_at(he) (he)->at
0
+ #define ANHE_at_cache(he)
0
@@ -467,6 +565,8 @@ ev_sleep (ev_tstamp delay)
0
/*****************************************************************************/
0
+#define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */
0
array_nextsize (int elem, int cur, int cnt)
0
@@ -476,11 +576,11 @@ array_nextsize (int elem, int cur, int cnt)
0
- /* if size > 4096, round to 4096 - 4 * longs to accomodate malloc overhead */
0
- if (elem * ncur > 4096)
0
+ /* if size is large, round to MALLOC_ROUND - 4 * longs to accomodate malloc overhead */
0
+ if (elem * ncur > MALLOC_ROUND - sizeof (void *) * 4)
0
- ncur = (ncur + elem +
4095 + sizeof (void *) * 4) & ~4095;
0
+ ncur = (ncur + elem +
(MALLOC_ROUND - 1) + sizeof (void *) * 4) & ~(MALLOC_ROUND - 1);
0
ncur = ncur - sizeof (void *) * 4;
0
@@ -704,60 +804,146 @@ fd_rearm_all (EV_P)
0
/*****************************************************************************/
0
+ * the heap functions want a real array index. array index 0 uis guaranteed to not
0
+ * be in-use at any time. the first heap entry is at array [HEAP0]. DHEAP gives
0
+ * the branching factor of the d-tree.
0
+ * at the moment we allow libev the luxury of two heaps,
0
+ * a small-code-size 2-heap one and a ~1.5kb larger 4-heap
0
+ * which is more cache-efficient.
0
+ * the difference is about 5% with 50000+ watchers.
0
+#define HEAP0 (DHEAP - 1) /* index of first element in heap */
0
+#define HPARENT(k) ((((k) - HEAP0 - 1) / DHEAP) + HEAP0)
0
+#define UPHEAP_DONE(p,k) ((p) == (k))
0
+/* away from the root */
0
-
upheap (WT *heap, int k)