# define EV_USE_REALTIME 0
#endif
-#if EV_SELECT_IS_WINSOCKET
-# include <winsock.h>
-#endif
-
#if !EV_STAT_ENABLE
+# undef EV_USE_INOTIFY
# define EV_USE_INOTIFY 0
#endif
# include <sys/inotify.h>
#endif
+#if EV_SELECT_IS_WINSOCKET
+# include <winsock.h>
+#endif
+
/**/
/*
#define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */
/*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds, TODO */
-#if __GNUC__ >= 3
+#if __GNUC__ >= 4
# define expect(expr,value) __builtin_expect ((expr),(value))
# define noinline __attribute__ ((noinline))
#else
ANFD *anfd = anfds + fd;
ev_io *w;
- int events = 0;
+ unsigned char events = 0;
for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next)
- events |= w->events;
+ events |= (unsigned char)w->events;
#if EV_SELECT_IS_WINSOCKET
if (events)
}
#endif
- anfd->reify = 0;
+ {
+ unsigned char o_events = anfd->events;
+ unsigned char o_reify = anfd->reify;
+
+ anfd->reify = 0;
+ anfd->events = events;
- backend_modify (EV_A_ fd, anfd->events, events);
- anfd->events = events;
+ if (o_events != events || o_reify & EV_IOFDSET)
+ backend_modify (EV_A_ fd, o_events, events);
+ }
}
fdchangecnt = 0;
}
void inline_size
-fd_change (EV_P_ int fd)
+fd_change (EV_P_ int fd, int flags)
{
- if (expect_false (anfds [fd].reify))
- return;
-
- anfds [fd].reify = 1;
+ unsigned char reify = anfds [fd].reify;
+ anfds [fd].reify |= flags;
- ++fdchangecnt;
- array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2);
- fdchanges [fdchangecnt - 1] = fd;
+ if (expect_true (!reify))
+ {
+ ++fdchangecnt;
+ array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2);
+ fdchanges [fdchangecnt - 1] = fd;
+ }
}
void inline_speed
if (anfds [fd].events)
{
anfds [fd].events = 0;
- fd_change (EV_A_ fd);
+ fd_change (EV_A_ fd, EV_IOFDSET | 1);
}
}
unsigned int
ev_embeddable_backends (void)
{
- return EVBACKEND_EPOLL
- | EVBACKEND_KQUEUE
+ /* epoll embeddability broken on all linux versions up to at least 2.6.23 */
+ return EVBACKEND_KQUEUE
| EVBACKEND_PORT;
}
#endif
}
+ ev_free (anfds); anfdmax = 0;
+
/* have to use the microsoft-never-gets-it-right macro */
array_free (fdchange, EMPTY);
array_free (timer, EMPTY);
#if EV_PERIODIC_ENABLE
array_free (periodic, EMPTY);
+#endif
+#if EV_FORK_ENABLE
+ array_free (fork, EMPTY);
#endif
array_free (prepare, EMPTY);
array_free (check, EMPTY);
array_needsize (ANFD, anfds, anfdmax, fd + 1, anfds_init);
wlist_add (&anfds[fd].head, (WL)w);
- fd_change (EV_A_ fd);
+ fd_change (EV_A_ fd, w->events & EV_IOFDSET | 1);
+ w->events &= ~EV_IOFDSET;
}
void noinline
wlist_del (&anfds[w->fd].head, (WL)w);
ev_stop (EV_A_ (W)w);
- fd_change (EV_A_ w->fd);
+ fd_change (EV_A_ w->fd, 1);
}
void noinline
void noinline
ev_embed_sweep (EV_P_ ev_embed *w)
{
- ev_loop (w->loop, EVLOOP_NONBLOCK);
+ ev_loop (w->other, EVLOOP_NONBLOCK);
}
static void
-embed_cb (EV_P_ ev_io *io, int revents)
+embed_io_cb (EV_P_ ev_io *io, int revents)
{
ev_embed *w = (ev_embed *)(((char *)io) - offsetof (ev_embed, io));
ev_embed_sweep (loop, w);
}
+static void
+embed_prepare_cb (EV_P_ ev_prepare *prepare, int revents)
+{
+ ev_embed *w = (ev_embed *)(((char *)prepare) - offsetof (ev_embed, prepare));
+
+ fd_reify (w->other);
+}
+
void
ev_embed_start (EV_P_ ev_embed *w)
{
return;
{
- struct ev_loop *loop = w->loop;
+ struct ev_loop *loop = w->other;
assert (("loop to be embedded is not embeddable", backend & ev_embeddable_backends ()));
- ev_io_init (&w->io, embed_cb, backend_fd, EV_READ);
+ ev_io_init (&w->io, embed_io_cb, backend_fd, EV_READ);
}
ev_set_priority (&w->io, ev_priority (w));
ev_io_start (EV_A_ &w->io);
+ ev_prepare_init (&w->prepare, embed_prepare_cb);
+ ev_set_priority (&w->prepare, EV_MINPRI);
+ ev_prepare_start (EV_A_ &w->prepare);
+
ev_start (EV_A_ (W)w, 1);
}
return;
ev_io_stop (EV_A_ &w->io);
+ ev_prepare_stop (EV_A_ &w->prepare);
ev_stop (EV_A_ (W)w);
}
}
}
+#if EV_MULTIPLICITY
+ #include "ev_wrap.h"
+#endif
+
#ifdef __cplusplus
}
#endif