Skip to content

Commit

Permalink
Upgrade to libev 4.04
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri committed Aug 10, 2011
1 parent a8734e6 commit f3b96eb
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 86 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -8,6 +8,7 @@
* Refactor StatWatcher to pass pervious and current path state ala Node.js
* spec:valgrind Rake task to run specs under valgrind
* Use rake-compiler to build cool.io
* Upgrade to libev 4.04

1.0.0
-----
Expand Down
24 changes: 24 additions & 0 deletions ext/libev/Changes
@@ -1,5 +1,29 @@
Revision history for libev, a high-performance and full-featured event loop.

4.04 Wed Feb 16 09:01:51 CET 2011
- fix two problems in the native win32 backend, where reuse of fd's
with different underlying handles caused handles not to be removed
or added to the select set (analyzed and tested by Bert Belder).
- do no rely on ceil() in ev_e?poll.c.
- backport libev to HP-UX versions before 11 v3.
- configure did not detect nanosleep and clock_gettime properly when
they are available in the libc (as opposed to -lrt).

4.03 Tue Jan 11 14:37:25 CET 2011
- officially support polling files with all backends.
- support files, /dev/zero etc. the same way as select in the epoll
backend, by generating events on our own.
- ports backend: work around solaris bug 6874410 and many related ones
(EINTR, maybe more), with no performance loss (note that the solaris
bug report is actually wrong, reality is far more bizarre and broken
than that).
- define EV_READ/EV_WRITE as macros in event.h, as some programs use
#ifdef to test for them.
- new (experimental) function: ev_feed_signal.
- new (to become default) EVFLAG_NOSIGMASK flag.
- new EVBACKEND_MASK symbol.
- updated COMMON IDIOMS SECTION.

4.01 Fri Nov 5 21:51:29 CET 2010
- automake fucked it up, apparently, --add-missing -f is not quite enough
to make it update its files, so 4.00 didn't install ev++.h and
Expand Down
110 changes: 78 additions & 32 deletions ext/libev/ev.c
@@ -1,19 +1,19 @@
/*
* libev event processing core, watcher management
*
* Copyright (c) 2007,2008,2009,2010 Marc Alexander Lehmann <libev@schmorp.de>
* Copyright (c) 2007,2008,2009,2010,2011 Marc Alexander Lehmann <libev@schmorp.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
* CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
Expand Down Expand Up @@ -378,7 +378,8 @@ EV_CPP(extern "C" {)
#endif

#if !EV_USE_NANOSLEEP
# ifndef _WIN32
/* hp-ux has it in sys/time.h, which we unconditionally include above */
# if !defined(_WIN32) && !defined(__hpux)
# include <sys/select.h>
# endif
#endif
Expand Down Expand Up @@ -817,6 +818,14 @@ ev_sleep (ev_tstamp delay)
}
}

inline_speed int
ev_timeout_to_ms (ev_tstamp timeout)
{
int ms = timeout * 1000. + .999999;

return expect_true (ms) ? ms : timeout < 1e-6 ? 0 : 1;
}

/*****************************************************************************/

#define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */
Expand Down Expand Up @@ -967,6 +976,31 @@ fd_reify (EV_P)
{
int i;

#if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP
for (i = 0; i < fdchangecnt; ++i)
{
int fd = fdchanges [i];
ANFD *anfd = anfds + fd;

if (anfd->reify & EV__IOFDSET)
{
SOCKET handle = EV_FD_TO_WIN32_HANDLE (fd);

if (handle != anfd->handle)
{
unsigned long arg;

assert (("libev: only socket fds supported in this configuration", ioctlsocket (handle, FIONREAD, &arg) == 0));

/* handle changed, but fd didn't - we need to do it in two steps */
backend_modify (EV_A_ fd, anfd->events, 0);
anfd->events = 0;
anfd->handle = handle;
}
}
}
#endif

for (i = 0; i < fdchangecnt; ++i)
{
int fd = fdchanges [i];
Expand All @@ -978,16 +1012,6 @@ fd_reify (EV_P)

anfd->reify = 0;

#if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP
if (o_reify & EV__IOFDSET)
{
unsigned long arg;
anfd->handle = EV_FD_TO_WIN32_HANDLE (fd);
assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0));
printf ("oi %d %x\n", fd, anfd->handle);//D
}
#endif

/*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */
{
anfd->events = 0;
Expand Down Expand Up @@ -1345,14 +1369,16 @@ pipecb (EV_P_ ev_io *iow, int revents)
read (evpipe [0], &dummy, 1);
}

#if EV_SIGNAL_ENABLE
if (sig_pending)
{
{
sig_pending = 0;

for (i = EV_NSIG - 1; i--; )
if (expect_false (signals [i].pending))
ev_feed_signal_event (EV_A_ i + 1);
}
#endif

#if EV_ASYNC_ENABLE
if (async_pending)
Expand All @@ -1371,19 +1397,28 @@ pipecb (EV_P_ ev_io *iow, int revents)

/*****************************************************************************/

static void
ev_sighandler (int signum)
void
ev_feed_signal (int signum)
{
#if EV_MULTIPLICITY
EV_P = signals [signum - 1].loop;

if (!EV_A)
return;
#endif

signals [signum - 1].pending = 1;
evpipe_write (EV_A_ &sig_pending);
}

static void
ev_sighandler (int signum)
{
#ifdef _WIN32
signal (signum, ev_sighandler);
#endif

signals [signum - 1].pending = 1;
evpipe_write (EV_A_ &sig_pending);
ev_feed_signal (signum);
}

void noinline
Expand Down Expand Up @@ -1645,6 +1680,8 @@ loop_init (EV_P_ unsigned int flags)
{
if (!backend)
{
origflags = flags;

#if EV_USE_REALTIME
if (!have_realtime)
{
Expand Down Expand Up @@ -1699,7 +1736,7 @@ loop_init (EV_P_ unsigned int flags)
sigfd = flags & EVFLAG_SIGNALFD ? -2 : -1;
#endif

if (!(flags & 0x0000ffffU))
if (!(flags & EVBACKEND_MASK))
flags |= ev_recommended_backends ();

#if EV_USE_IOCP
Expand Down Expand Up @@ -2102,9 +2139,6 @@ ev_invoke_pending (EV_P)
{
ANPENDING *p = pendings [pri] + --pendingcnt [pri];

/*assert (("libev: non-pending watcher on pending list", p->w->pending));*/
/* ^ this is no longer true, as pending_w could be here */

p->w->pending = 0;
EV_CB_INVOKE (p->w, p->events);
EV_FREQUENT_CHECK;
Expand Down Expand Up @@ -2175,6 +2209,15 @@ timers_reify (EV_P)
}

#if EV_PERIODIC_ENABLE

inline_speed void
periodic_recalc (EV_P_ ev_periodic *w)
{
/* TODO: use slow but potentially more correct incremental algo, */
/* also do not rely on ceil */
ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
}

/* make periodics pending */
inline_size void
periodics_reify (EV_P)
Expand Down Expand Up @@ -2203,7 +2246,8 @@ periodics_reify (EV_P)
}
else if (w->interval)
{
ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
periodic_recalc (EV_A_ w);

/* if next trigger time is not sufficiently in the future, put it there */
/* this might happen because of floating point inexactness */
if (ev_at (w) - ev_rt_now < TIME_EPSILON)
Expand Down Expand Up @@ -2247,7 +2291,7 @@ periodics_reschedule (EV_P)
if (w->reschedule_cb)
ev_at (w) = w->reschedule_cb (w, ev_rt_now);
else if (w->interval)
ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
periodic_recalc (EV_A_ w);

ANHE_at_cache (periodics [i]);
}
Expand Down Expand Up @@ -2749,8 +2793,7 @@ ev_periodic_start (EV_P_ ev_periodic *w)
else if (w->interval)
{
assert (("libev: ev_periodic_start called with negative interval value", w->interval >= 0.));
/* this formula differs from the one in periodic_reify because we do not always round up */
ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
periodic_recalc (EV_A_ w);
}
else
ev_at (w) = w->offset;
Expand Down Expand Up @@ -2881,9 +2924,12 @@ ev_signal_start (EV_P_ ev_signal *w)
sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */
sigaction (w->signum, &sa, 0);

sigemptyset (&sa.sa_mask);
sigaddset (&sa.sa_mask, w->signum);
sigprocmask (SIG_UNBLOCK, &sa.sa_mask, 0);
if (origflags & EVFLAG_NOSIGMASK)
{
sigemptyset (&sa.sa_mask);
sigaddset (&sa.sa_mask, w->signum);
sigprocmask (SIG_UNBLOCK, &sa.sa_mask, 0);
}
#endif
}

Expand Down Expand Up @@ -3034,7 +3080,7 @@ infy_add (EV_P_ ev_stat *w)

*pend = 0;
w->wd = inotify_add_watch (fs_fd, path, mask);
}
}
while (w->wd < 0 && (errno == ENOENT || errno == EACCES));
}
}
Expand Down
19 changes: 11 additions & 8 deletions ext/libev/ev.h
@@ -1,19 +1,19 @@
/*
* libev native API header
*
* Copyright (c) 2007,2008,2009,2010 Marc Alexander Lehmann <libev@schmorp.de>
* Copyright (c) 2007,2008,2009,2010,2011 Marc Alexander Lehmann <libev@schmorp.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
* CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
Expand Down Expand Up @@ -185,15 +185,15 @@ struct ev_loop;
# define EV_INLINE static
#endif

/* EV_PROTOTYPES can be sued to switch of prototype declarations */
/* EV_PROTOTYPES can be used to switch of prototype declarations */
#ifndef EV_PROTOTYPES
# define EV_PROTOTYPES 1
#endif

/*****************************************************************************/

#define EV_VERSION_MAJOR 4
#define EV_VERSION_MINOR 1
#define EV_VERSION_MINOR 4

/* eventmask, revents, events... */
enum {
Expand Down Expand Up @@ -491,7 +491,8 @@ enum {
#if EV_COMPAT3
EVFLAG_NOSIGFD = 0, /* compatibility to pre-3.9 */
#endif
EVFLAG_SIGNALFD = 0x00200000U /* attempt to use signalfd */
EVFLAG_SIGNALFD = 0x00200000U, /* attempt to use signalfd */
EVFLAG_NOSIGMASK = 0x00400000U /* avoid modifying the signal mask */
};

/* method bits to be ored together */
Expand All @@ -502,7 +503,8 @@ enum {
EVBACKEND_KQUEUE = 0x00000008U, /* bsd */
EVBACKEND_DEVPOLL = 0x00000010U, /* solaris 8 */ /* NYI */
EVBACKEND_PORT = 0x00000020U, /* solaris 10 */
EVBACKEND_ALL = 0x0000003FU
EVBACKEND_ALL = 0x0000003FU, /* all known backends */
EVBACKEND_MASK = 0x0000FFFFU /* all future backends */
};

#if EV_PROTOTYPES
Expand Down Expand Up @@ -720,6 +722,7 @@ void ev_resume (EV_P);
void ev_feed_event (EV_P_ void *w, int revents);
void ev_feed_fd_event (EV_P_ int fd, int revents);
#if EV_SIGNAL_ENABLE
void ev_feed_signal (int signum);
void ev_feed_signal_event (EV_P_ int signum);
#endif
void ev_invoke (EV_P_ void *w, int revents);
Expand Down

0 comments on commit f3b96eb

Please sign in to comment.