X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/fa5f32e568e5e1f7bcb548b108379c434d253731..5aeb50d21d1ef0b2fff324f21c608967dcfeb60c:/ev.c?ds=sidebyside diff --git a/ev.c b/ev.c index 8c3bf01..9674c7c 100644 --- a/ev.c +++ b/ev.c @@ -60,13 +60,17 @@ # 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" @@ -115,8 +119,7 @@ get_clock (void) 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) \ @@ -124,7 +127,7 @@ get_clock (void) int newcnt = cur; \ do \ { \ - newcnt = array_nextsize (newcnt); \ + newcnt = array_roundsize (base, newcnt << 1); \ } \ while ((cnt) > newcnt); \ \ @@ -167,13 +170,16 @@ static int pendingmax, pendingcnt; 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 @@ -257,8 +263,8 @@ fd_recheck (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); } } @@ -531,8 +537,6 @@ timers_reify (void) { struct ev_timer *w = timers [0]; - event ((W)w, EV_TIMEOUT); - /* first reschedule or stop timer */ if (w->repeat) { @@ -542,6 +546,8 @@ timers_reify (void) } else ev_timer_stop (w); /* nonrepeating: stop timer */ + + event ((W)w, EV_TIMEOUT); } }