# 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;
+ unsigned char reify = anfds [fd].reify;
+ anfds [fd].reify |= flags;
- anfds [fd].reify = 1;
-
- ++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);
}
}
heap [k] = w;
((W)heap [k])->active = k + 1;
-
}
void inline_speed
/*****************************************************************************/
-static ev_child *childs [EV_PID_HASHSIZE];
+static WL childs [EV_PID_HASHSIZE];
#ifndef _WIN32
#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);
{
while (timercnt && ((WT)timers [0])->at <= mn_now)
{
- ev_timer *w = timers [0];
+ ev_timer *w = (ev_timer *)timers [0];
/*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/
if (((WT)w)->at < mn_now)
((WT)w)->at = mn_now;
- downheap ((WT *)timers, timercnt, 0);
+ downheap (timers, timercnt, 0);
}
else
ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */
{
while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now)
{
- ev_periodic *w = periodics [0];
+ ev_periodic *w = (ev_periodic *)periodics [0];
/*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/
{
((WT)w)->at = w->reschedule_cb (w, ev_rt_now + TIME_EPSILON);
assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now));
- downheap ((WT *)periodics, periodiccnt, 0);
+ downheap (periodics, periodiccnt, 0);
}
else if (w->interval)
{
((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
if (((WT)w)->at - ev_rt_now <= TIME_EPSILON) ((WT)w)->at += w->interval;
assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > ev_rt_now));
- downheap ((WT *)periodics, periodiccnt, 0);
+ downheap (periodics, periodiccnt, 0);
}
else
ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */
/* adjust periodics after time jump */
for (i = 0; i < periodiccnt; ++i)
{
- ev_periodic *w = periodics [i];
+ ev_periodic *w = (ev_periodic *)periodics [i];
if (w->reschedule_cb)
((WT)w)->at = w->reschedule_cb (w, ev_rt_now);
/* now rebuild the heap */
for (i = periodiccnt >> 1; i--; )
- downheap ((WT *)periodics, periodiccnt, i);
+ downheap (periodics, periodiccnt, i);
}
#endif
ev_start (EV_A_ (W)w, 1);
array_needsize (ANFD, anfds, anfdmax, fd + 1, anfds_init);
- wlist_add ((WL *)&anfds[fd].head, (WL)w);
+ 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
assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax));
- wlist_del ((WL *)&anfds[w->fd].head, (WL)w);
+ 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
assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.));
ev_start (EV_A_ (W)w, ++timercnt);
- array_needsize (ev_timer *, timers, timermax, timercnt, EMPTY2);
- timers [timercnt - 1] = w;
- upheap ((WT *)timers, timercnt - 1);
+ array_needsize (WT, timers, timermax, timercnt, EMPTY2);
+ timers [timercnt - 1] = (WT)w;
+ upheap (timers, timercnt - 1);
/*assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));*/
}
if (expect_false (!ev_is_active (w)))
return;
- assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
+ assert (("internal timer heap corruption", timers [((W)w)->active - 1] == (WT)w));
{
int active = ((W)w)->active;
if (expect_true (--active < --timercnt))
{
timers [active] = timers [timercnt];
- adjustheap ((WT *)timers, timercnt, active);
+ adjustheap (timers, timercnt, active);
}
}
if (w->repeat)
{
((WT)w)->at = mn_now + w->repeat;
- adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1);
+ adjustheap (timers, timercnt, ((W)w)->active - 1);
}
else
ev_timer_stop (EV_A_ w);
((WT)w)->at = w->offset;
ev_start (EV_A_ (W)w, ++periodiccnt);
- array_needsize (ev_periodic *, periodics, periodicmax, periodiccnt, EMPTY2);
- periodics [periodiccnt - 1] = w;
- upheap ((WT *)periodics, periodiccnt - 1);
+ array_needsize (WT, periodics, periodicmax, periodiccnt, EMPTY2);
+ periodics [periodiccnt - 1] = (WT)w;
+ upheap (periodics, periodiccnt - 1);
/*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/
}
if (expect_false (!ev_is_active (w)))
return;
- assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
+ assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == (WT)w));
{
int active = ((W)w)->active;
if (expect_true (--active < --periodiccnt))
{
periodics [active] = periodics [periodiccnt];
- adjustheap ((WT *)periodics, periodiccnt, active);
+ adjustheap (periodics, periodiccnt, active);
}
}
assert (("ev_signal_start called with illegal signal number", w->signum > 0));
+ {
+#ifndef _WIN32
+ sigset_t full, prev;
+ sigfillset (&full);
+ sigprocmask (SIG_SETMASK, &full, &prev);
+#endif
+
+ array_needsize (ANSIG, signals, signalmax, w->signum, signals_init);
+
+#ifndef _WIN32
+ sigprocmask (SIG_SETMASK, &prev, 0);
+#endif
+ }
+
ev_start (EV_A_ (W)w, 1);
- array_needsize (ANSIG, signals, signalmax, w->signum, signals_init);
- wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w);
+ wlist_add (&signals [w->signum - 1].head, (WL)w);
if (!((WL)w)->next)
{
if (expect_false (!ev_is_active (w)))
return;
- wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w);
+ wlist_del (&signals [w->signum - 1].head, (WL)w);
ev_stop (EV_A_ (W)w);
if (!signals [w->signum - 1].head)
return;
ev_start (EV_A_ (W)w, 1);
- wlist_add ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w);
+ wlist_add (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w);
}
void
if (expect_false (!ev_is_active (w)))
return;
- wlist_del ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w);
+ wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w);
ev_stop (EV_A_ (W)w);
}
void noinline
ev_embed_sweep (EV_P_ ev_embed *w)
{
- ev_loop (w->loop, EVLOOP_NONBLOCK);
+ ev_loop (w->other, EVLOOP_NONBLOCK);
}
static void
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);
}
}
}
+#if EV_MULTIPLICITY
+ #include "ev_wrap.h"
+#endif
+
#ifdef __cplusplus
}
#endif