# define EV_USE_EPOLL 0
#endif
+#ifndef CLOCK_REALTIME
+# define EV_USE_REALTIME 0
+#endif
#ifndef EV_USE_REALTIME
# define EV_USE_REALTIME 1 /* posix requirement, but might be slower */
#endif
#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
-#define MAX_BLOCKTIME 59.731
-#define PID_HASHSIZE 16 /* size of pid hahs table, must be power of two */
+#define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detetc time jumps) */
+#define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */
+#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds */
#include "ev.h"
return ev_time ();
}
-#define array_nextsize(n) (((n) << 1) | 4 & ~3)
-#define array_prevsize(n) (((n) >> 1) | 4 & ~3)
+#define array_roundsize(base,n) ((n) | 4 & ~3)
#define array_needsize(base,cur,cnt,init) \
if ((cnt) > cur) \
int newcnt = cur; \
do \
{ \
- newcnt = array_nextsize (newcnt); \
+ newcnt = array_roundsize (base, newcnt << 1); \
} \
while ((cnt) > newcnt); \
\
static void
event (W w, int events)
{
- if (w->active)
+ if (w->pending)
{
- w->pending = ++pendingcnt;
- array_needsize (pendings, pendingmax, pendingcnt, );
- pendings [pendingcnt - 1].w = w;
- pendings [pendingcnt - 1].events = events;
+ pendings [w->pending - 1].events |= events;
+ return;
}
+
+ w->pending = ++pendingcnt;
+ array_needsize (pendings, pendingmax, pendingcnt, );
+ pendings [pendingcnt - 1].w = w;
+ pendings [pendingcnt - 1].events = events;
}
static void
if (fcntl (fd, F_GETFD) == -1 && errno == EBADF)
while (anfds [fd].head)
{
- event ((W)anfds [fd].head, EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT);
ev_io_stop (anfds [fd].head);
+ event ((W)anfds [fd].head, EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT);
}
}
{
struct ev_timer *w = timers [0];
- event ((W)w, EV_TIMEOUT);
-
/* first reschedule or stop timer */
if (w->repeat)
{
}
else
ev_timer_stop (w); /* nonrepeating: stop timer */
+
+ event ((W)w, EV_TIMEOUT);
}
}