… | |
… | |
58 | |
58 | |
59 | #ifndef EV_USE_EPOLL |
59 | #ifndef EV_USE_EPOLL |
60 | # define EV_USE_EPOLL 0 |
60 | # define EV_USE_EPOLL 0 |
61 | #endif |
61 | #endif |
62 | |
62 | |
|
|
63 | #ifndef CLOCK_REALTIME |
|
|
64 | # define EV_USE_REALTIME 0 |
|
|
65 | #endif |
63 | #ifndef EV_USE_REALTIME |
66 | #ifndef EV_USE_REALTIME |
64 | # define EV_USE_REALTIME 1 /* posix requirement, but might be slower */ |
67 | # define EV_USE_REALTIME 1 /* posix requirement, but might be slower */ |
65 | #endif |
68 | #endif |
66 | |
69 | |
67 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
70 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
68 | #define MAX_BLOCKTIME 59.731 |
71 | #define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detetc time jumps) */ |
69 | #define PID_HASHSIZE 16 /* size of pid hahs table, must be power of two */ |
72 | #define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */ |
|
|
73 | #define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds */ |
70 | |
74 | |
71 | #include "ev.h" |
75 | #include "ev.h" |
72 | |
76 | |
73 | typedef struct ev_watcher *W; |
77 | typedef struct ev_watcher *W; |
74 | typedef struct ev_watcher_list *WL; |
78 | typedef struct ev_watcher_list *WL; |
… | |
… | |
164 | static int pendingmax, pendingcnt; |
168 | static int pendingmax, pendingcnt; |
165 | |
169 | |
166 | static void |
170 | static void |
167 | event (W w, int events) |
171 | event (W w, int events) |
168 | { |
172 | { |
|
|
173 | if (w->pending) |
|
|
174 | { |
|
|
175 | pendings [w->pending - 1].events |= events; |
|
|
176 | return; |
|
|
177 | } |
|
|
178 | |
169 | w->pending = ++pendingcnt; |
179 | w->pending = ++pendingcnt; |
170 | array_needsize (pendings, pendingmax, pendingcnt, ); |
180 | array_needsize (pendings, pendingmax, pendingcnt, ); |
171 | pendings [pendingcnt - 1].w = w; |
181 | pendings [pendingcnt - 1].w = w; |
172 | pendings [pendingcnt - 1].events = events; |
182 | pendings [pendingcnt - 1].events = events; |
173 | } |
183 | } |
… | |
… | |
251 | for (fd = 0; fd < anfdmax; ++fd) |
261 | for (fd = 0; fd < anfdmax; ++fd) |
252 | if (anfds [fd].events) |
262 | if (anfds [fd].events) |
253 | if (fcntl (fd, F_GETFD) == -1 && errno == EBADF) |
263 | if (fcntl (fd, F_GETFD) == -1 && errno == EBADF) |
254 | while (anfds [fd].head) |
264 | while (anfds [fd].head) |
255 | { |
265 | { |
|
|
266 | ev_io_stop (anfds [fd].head); |
256 | event ((W)anfds [fd].head, EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT); |
267 | event ((W)anfds [fd].head, EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT); |
257 | ev_io_stop (anfds [fd].head); |
|
|
258 | } |
268 | } |
259 | } |
269 | } |
260 | |
270 | |
261 | /*****************************************************************************/ |
271 | /*****************************************************************************/ |
262 | |
272 | |