This commit is contained in:
Marc Alexander Lehmann 2007-10-31 20:46:44 +00:00
parent 471dfc58ca
commit 1f357b803c
5 changed files with 58 additions and 25 deletions

5
Changes Normal file
View File

@ -0,0 +1,5 @@
Revision history for libev, a high-performance and full-featured event loop
0.1 Wed Oct 31 21:31:48 CET 2007
- original version; hacked together in <24h.

36
ev.c
View File

@ -199,7 +199,7 @@ queue_events (W *events, int eventcnt, int type)
/* called on EBADF to verify fds */
static void
fd_recheck ()
fd_recheck (void)
{
int fd;
@ -207,7 +207,10 @@ fd_recheck ()
if (anfds [fd].wev)
if (fcntl (fd, F_GETFD) == -1 && errno == EBADF)
while (anfds [fd].head)
evio_stop (anfds [fd].head);
{
event ((W)anfds [fd].head, EV_ERROR);
evio_stop (anfds [fd].head);
}
}
/*****************************************************************************/
@ -374,6 +377,18 @@ childcb (struct ev_signal *sw, int revents)
# include "ev_select.c"
#endif
int
ev_version_major (void)
{
return EV_VERSION_MAJOR;
}
int
ev_version_minor (void)
{
return EV_VERSION_MINOR;
}
int ev_init (int flags)
{
if (!ev_method)
@ -416,17 +431,20 @@ int ev_init (int flags)
/*****************************************************************************/
void ev_prefork (void)
void
ev_prefork (void)
{
/* nop */
}
void ev_postfork_parent (void)
void
ev_postfork_parent (void)
{
/* nop */
}
void ev_postfork_child (void)
void
ev_postfork_child (void)
{
#if HAVE_EPOLL
if (ev_method == EVMETHOD_EPOLL)
@ -469,7 +487,7 @@ fd_reify (void)
}
static void
call_pending ()
call_pending (void)
{
while (pendingcnt)
{
@ -484,7 +502,7 @@ call_pending ()
}
static void
timers_reify ()
timers_reify (void)
{
while (timercnt && timers [0]->at <= now)
{
@ -505,7 +523,7 @@ timers_reify ()
}
static void
periodics_reify ()
periodics_reify (void)
{
while (periodiccnt && periodics [0]->at <= ev_now)
{
@ -551,7 +569,7 @@ periodics_reschedule (ev_tstamp diff)
}
static void
time_update ()
time_update (void)
{
int i;

25
ev.h
View File

@ -34,16 +34,16 @@ typedef double ev_tstamp;
/* eventmask, revents, events... */
#define EV_UNDEF -1 /* guaranteed to be invalid */
#define EV_NONE 0x00
#define EV_READ 0x01
#define EV_WRITE 0x02
#define EV_TIMEOUT 0x04
#define EV_SIGNAL 0x08
#define EV_IDLE 0x10
#define EV_CHECK 0x20
#define EV_PREPARE 0x40
#define EV_CHILD 0x80
#define EV_ERROR (0xff|0x8000)
#define EV_NONE 0x000000
#define EV_READ 0x000001
#define EV_WRITE 0x000002
#define EV_TIMEOUT 0x000004
#define EV_SIGNAL 0x000008
#define EV_IDLE 0x000010
#define EV_CHECK 0x000020
#define EV_PREPARE 0x000040
#define EV_CHILD 0x000080
#define EV_ERROR 0x800000
/* can be used to add custom fields to all watchers */
#ifndef EV_COMMON
@ -53,6 +53,9 @@ typedef double ev_tstamp;
# define EV_PROTOTYPES 1
#endif
#define EV_VERSION_MAJOR 1
#define EV_VERSION_MINOR 1
/*
* struct member types:
* private: you can look at them, but not change them, and they might not mean anything to you.
@ -157,6 +160,8 @@ struct ev_child
#if EV_PROTOTYPES
extern int ev_method;
int ev_init (int flags); /* returns ev_method */
int ev_version_major (void);
int ev_version_minor (void);
/* these three calls are suitable for plugging into pthread_atfork */
void ev_prefork (void);

View File

@ -45,7 +45,8 @@ epoll_modify (int fd, int oev, int nev)
epoll_ctl (epoll_fd, mode, fd, &ev);
}
void epoll_postfork_child (void)
static void
epoll_postfork_child (void)
{
int fd;
@ -61,7 +62,8 @@ void epoll_postfork_child (void)
static struct epoll_event *events;
static int eventmax;
static void epoll_poll (ev_tstamp timeout)
static void
epoll_poll (ev_tstamp timeout)
{
int eventcnt = epoll_wait (epoll_fd, events, eventmax, ceil (timeout * 1000.));
int i;
@ -85,7 +87,8 @@ static void epoll_poll (ev_tstamp timeout)
}
}
void epoll_init (int flags)
static void
epoll_init (int flags)
{
epoll_fd = epoll_create (256);
@ -102,3 +105,4 @@ void epoll_init (int flags)
eventmax = 64; /* intiial number of events receivable per poll */
events = malloc (sizeof (struct epoll_event) * eventmax);
}

View File

@ -70,7 +70,8 @@ select_modify (int fd, int oev, int nev)
vec_wi [offs] &= ~mask;
}
static void select_poll (ev_tstamp timeout)
static void
select_poll (ev_tstamp timeout)
{
struct timeval tv;
int res;
@ -117,7 +118,8 @@ static void select_poll (ev_tstamp timeout)
}
}
void select_init (int flags)
static void
select_init (int flags)
{
ev_method = EVMETHOD_SELECT;
method_fudge = 1e-2; /* needed to compensate for select returning early, very conservative */
@ -125,4 +127,3 @@ void select_init (int flags)
method_poll = select_poll;
}