libev/ev.c

1133 lines
22 KiB
C
Raw Normal View History

2007-10-31 14:44:14 +00:00
/*
* Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * 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 COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if EV_USE_CONFIG_H
# include "config.h"
#endif
2007-10-31 14:44:14 +00:00
#include <math.h>
#include <stdlib.h>
2007-10-31 00:24:16 +00:00
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
2007-10-31 13:57:34 +00:00
#include <stddef.h>
#include <stdio.h>
2007-10-30 23:10:33 +00:00
#include <assert.h>
#include <errno.h>
2007-10-31 19:07:43 +00:00
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <time.h>
#ifndef EV_USE_MONOTONIC
# ifdef CLOCK_MONOTONIC
# define EV_USE_MONOTONIC 1
# endif
#endif
#ifndef EV_USE_SELECT
# define EV_USE_SELECT 1
#endif
#ifndef EV_USE_EPOLL
# define EV_USE_EPOLL 0
#endif
2007-11-01 09:05:33 +00:00
#ifndef CLOCK_REALTIME
# define EV_USE_REALTIME 0
#endif
#ifndef EV_USE_REALTIME
# define EV_USE_REALTIME 1 /* posix requirement, but might be slower */
#endif
2007-10-30 23:10:33 +00:00
#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
2007-11-01 09:05:33 +00:00
#define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detetc time jumps) */
#define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */
#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds */
#include "ev.h"
typedef struct ev_watcher *W;
typedef struct ev_watcher_list *WL;
2007-10-31 09:23:17 +00:00
typedef struct ev_watcher_time *WT;
2007-10-30 23:10:33 +00:00
static ev_tstamp now, diff; /* monotonic clock */
ev_tstamp ev_now;
int ev_method;
static int have_monotonic; /* runtime */
static ev_tstamp method_fudge; /* stupid epoll-returns-early bug */
2007-10-30 23:54:38 +00:00
static void (*method_modify)(int fd, int oev, int nev);
static void (*method_poll)(ev_tstamp timeout);
2007-10-31 00:32:33 +00:00
/*****************************************************************************/
ev_tstamp
ev_time (void)
{
#if EV_USE_REALTIME
struct timespec ts;
clock_gettime (CLOCK_REALTIME, &ts);
return ts.tv_sec + ts.tv_nsec * 1e-9;
#else
struct timeval tv;
gettimeofday (&tv, 0);
return tv.tv_sec + tv.tv_usec * 1e-6;
#endif
}
static ev_tstamp
get_clock (void)
{
#if EV_USE_MONOTONIC
if (have_monotonic)
{
struct timespec ts;
clock_gettime (CLOCK_MONOTONIC, &ts);
return ts.tv_sec + ts.tv_nsec * 1e-9;
}
#endif
return ev_time ();
}
#define array_roundsize(base,n) ((n) | 4 & ~3)
#define array_needsize(base,cur,cnt,init) \
if ((cnt) > cur) \
{ \
2007-10-31 20:10:17 +00:00
int newcnt = cur; \
do \
{ \
newcnt = array_roundsize (base, newcnt << 1); \
2007-10-31 20:10:17 +00:00
} \
while ((cnt) > newcnt); \
\
base = realloc (base, sizeof (*base) * (newcnt)); \
init (base + cur, newcnt - cur); \
cur = newcnt; \
}
2007-10-31 00:32:33 +00:00
/*****************************************************************************/
typedef struct
{
struct ev_io *head;
2007-10-31 22:16:36 +00:00
int events;
} ANFD;
static ANFD *anfds;
static int anfdmax;
static void
anfds_init (ANFD *base, int count)
{
while (count--)
{
2007-10-31 22:16:36 +00:00
base->head = 0;
base->events = EV_NONE;
++base;
}
}
typedef struct
{
W w;
int events;
} ANPENDING;
static ANPENDING *pendings;
static int pendingmax, pendingcnt;
static void
event (W w, int events)
{
w->pending = ++pendingcnt;
array_needsize (pendings, pendingmax, pendingcnt, );
pendings [pendingcnt - 1].w = w;
pendings [pendingcnt - 1].events = events;
}
2007-10-31 22:16:36 +00:00
static void
queue_events (W *events, int eventcnt, int type)
{
int i;
for (i = 0; i < eventcnt; ++i)
event (events [i], type);
}
static void
fd_event (int fd, int events)
{
ANFD *anfd = anfds + fd;
struct ev_io *w;
for (w = anfd->head; w; w = w->next)
{
int ev = w->events & events;
if (ev)
event ((W)w, ev);
}
}
2007-10-31 22:16:36 +00:00
/*****************************************************************************/
static int *fdchanges;
static int fdchangemax, fdchangecnt;
static void
2007-10-31 22:16:36 +00:00
fd_reify (void)
{
int i;
2007-10-31 22:16:36 +00:00
for (i = 0; i < fdchangecnt; ++i)
{
int fd = fdchanges [i];
ANFD *anfd = anfds + fd;
struct ev_io *w;
int events = 0;
for (w = anfd->head; w; w = w->next)
events |= w->events;
anfd->events &= ~EV_REIFY;
if (anfd->events != events)
{
method_modify (fd, anfd->events, events);
anfd->events = events;
}
}
fdchangecnt = 0;
}
static void
fd_change (int fd)
{
if (anfds [fd].events & EV_REIFY || fdchangecnt < 0)
2007-10-31 22:16:36 +00:00
return;
anfds [fd].events |= EV_REIFY;
++fdchangecnt;
array_needsize (fdchanges, fdchangemax, fdchangecnt, );
fdchanges [fdchangecnt - 1] = fd;
}
2007-10-31 17:55:55 +00:00
/* called on EBADF to verify fds */
static void
2007-10-31 20:46:44 +00:00
fd_recheck (void)
2007-10-31 17:55:55 +00:00
{
int fd;
for (fd = 0; fd < anfdmax; ++fd)
2007-10-31 22:16:36 +00:00
if (anfds [fd].events)
2007-10-31 17:55:55 +00:00
if (fcntl (fd, F_GETFD) == -1 && errno == EBADF)
while (anfds [fd].head)
2007-10-31 20:46:44 +00:00
{
event ((W)anfds [fd].head, EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT);
2007-11-01 06:48:49 +00:00
ev_io_stop (anfds [fd].head);
2007-10-31 20:46:44 +00:00
}
2007-10-31 17:55:55 +00:00
}
2007-10-31 00:32:33 +00:00
/*****************************************************************************/
2007-10-31 09:23:17 +00:00
static struct ev_timer **timers;
static int timermax, timercnt;
2007-10-30 23:10:33 +00:00
2007-10-31 09:23:17 +00:00
static struct ev_periodic **periodics;
static int periodicmax, periodiccnt;
static void
2007-10-31 09:23:17 +00:00
upheap (WT *timers, int k)
{
2007-10-31 09:23:17 +00:00
WT w = timers [k];
while (k && timers [k >> 1]->at > w->at)
{
timers [k] = timers [k >> 1];
timers [k]->active = k + 1;
k >>= 1;
}
timers [k] = w;
timers [k]->active = k + 1;
}
static void
2007-10-31 09:23:17 +00:00
downheap (WT *timers, int N, int k)
{
2007-10-31 09:23:17 +00:00
WT w = timers [k];
2007-10-30 23:10:33 +00:00
while (k < (N >> 1))
{
int j = k << 1;
2007-10-30 23:10:33 +00:00
if (j + 1 < N && timers [j]->at > timers [j + 1]->at)
++j;
if (w->at <= timers [j]->at)
break;
timers [k] = timers [j];
2007-10-30 21:42:12 +00:00
timers [k]->active = k + 1;
k = j;
}
timers [k] = w;
timers [k]->active = k + 1;
}
2007-10-31 00:32:33 +00:00
/*****************************************************************************/
2007-10-31 00:24:16 +00:00
typedef struct
{
struct ev_signal *head;
sig_atomic_t gotsig;
} ANSIG;
static ANSIG *signals;
2007-10-30 23:10:33 +00:00
static int signalmax;
2007-10-31 00:24:16 +00:00
static int sigpipe [2];
static sig_atomic_t gotsig;
static struct ev_io sigev;
static void
2007-10-31 00:24:16 +00:00
signals_init (ANSIG *base, int count)
{
while (count--)
2007-10-31 00:24:16 +00:00
{
base->head = 0;
base->gotsig = 0;
++base;
}
}
static void
sighandler (int signum)
{
signals [signum - 1].gotsig = 1;
if (!gotsig)
{
gotsig = 1;
write (sigpipe [1], &gotsig, 1);
}
}
static void
sigcb (struct ev_io *iow, int revents)
{
struct ev_signal *w;
int sig;
gotsig = 0;
read (sigpipe [0], &revents, 1);
for (sig = signalmax; sig--; )
if (signals [sig].gotsig)
{
signals [sig].gotsig = 0;
for (w = signals [sig].head; w; w = w->next)
event ((W)w, EV_SIGNAL);
2007-10-31 00:24:16 +00:00
}
}
static void
siginit (void)
{
fcntl (sigpipe [0], F_SETFD, FD_CLOEXEC);
fcntl (sigpipe [1], F_SETFD, FD_CLOEXEC);
/* rather than sort out wether we really need nb, set it */
fcntl (sigpipe [0], F_SETFL, O_NONBLOCK);
fcntl (sigpipe [1], F_SETFL, O_NONBLOCK);
2007-11-01 06:48:49 +00:00
ev_io_set (&sigev, sigpipe [0], EV_READ);
ev_io_start (&sigev);
}
2007-10-31 00:32:33 +00:00
/*****************************************************************************/
static struct ev_idle **idles;
static int idlemax, idlecnt;
2007-10-31 18:28:00 +00:00
static struct ev_prepare **prepares;
static int preparemax, preparecnt;
static struct ev_check **checks;
static int checkmax, checkcnt;
/*****************************************************************************/
2007-10-31 19:07:43 +00:00
static struct ev_child *childs [PID_HASHSIZE];
static struct ev_signal childev;
#ifndef WCONTINUED
# define WCONTINUED 0
#endif
static void
childcb (struct ev_signal *sw, int revents)
{
struct ev_child *w;
int pid, status;
while ((pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)) != -1)
for (w = childs [pid & (PID_HASHSIZE - 1)]; w; w = w->next)
if (w->pid == pid || w->pid == -1)
{
w->status = status;
event ((W)w, EV_CHILD);
}
}
/*****************************************************************************/
#if EV_USE_EPOLL
# include "ev_epoll.c"
#endif
#if EV_USE_SELECT
# include "ev_select.c"
#endif
2007-10-31 20:46:44 +00:00
int
ev_version_major (void)
{
return EV_VERSION_MAJOR;
}
int
ev_version_minor (void)
{
return EV_VERSION_MINOR;
}
int ev_init (int flags)
{
2007-10-31 20:10:17 +00:00
if (!ev_method)
{
#if EV_USE_MONOTONIC
2007-10-31 20:10:17 +00:00
{
struct timespec ts;
if (!clock_gettime (CLOCK_MONOTONIC, &ts))
have_monotonic = 1;
}
#endif
2007-10-31 20:10:17 +00:00
ev_now = ev_time ();
now = get_clock ();
diff = ev_now - now;
2007-10-31 20:10:17 +00:00
if (pipe (sigpipe))
return 0;
2007-10-31 00:24:16 +00:00
2007-10-31 20:10:17 +00:00
ev_method = EVMETHOD_NONE;
#if EV_USE_EPOLL
2007-10-31 20:10:17 +00:00
if (ev_method == EVMETHOD_NONE) epoll_init (flags);
#endif
#if EV_USE_SELECT
2007-10-31 20:10:17 +00:00
if (ev_method == EVMETHOD_NONE) select_init (flags);
#endif
2007-10-31 20:10:17 +00:00
if (ev_method)
{
2007-11-01 06:48:49 +00:00
ev_watcher_init (&sigev, sigcb);
2007-10-31 20:10:17 +00:00
siginit ();
2007-10-31 19:07:43 +00:00
2007-11-01 06:48:49 +00:00
ev_signal_init (&childev, childcb, SIGCHLD);
ev_signal_start (&childev);
2007-10-31 20:10:17 +00:00
}
2007-10-31 00:24:16 +00:00
}
return ev_method;
}
2007-10-31 00:32:33 +00:00
/*****************************************************************************/
2007-10-31 20:46:44 +00:00
void
ev_prefork (void)
{
2007-10-31 07:40:49 +00:00
/* nop */
}
2007-10-31 20:46:44 +00:00
void
ev_postfork_parent (void)
{
2007-10-31 07:40:49 +00:00
/* nop */
}
2007-10-31 20:46:44 +00:00
void
ev_postfork_child (void)
{
#if EV_USE_EPOLL
2007-10-30 23:54:38 +00:00
if (ev_method == EVMETHOD_EPOLL)
epoll_postfork_child ();
#endif
2007-10-31 00:24:16 +00:00
2007-11-01 06:48:49 +00:00
ev_io_stop (&sigev);
2007-10-31 00:24:16 +00:00
close (sigpipe [0]);
close (sigpipe [1]);
pipe (sigpipe);
siginit ();
}
2007-10-31 00:32:33 +00:00
/*****************************************************************************/
static void
2007-10-31 20:46:44 +00:00
call_pending (void)
{
2007-10-31 16:29:52 +00:00
while (pendingcnt)
{
2007-10-31 16:29:52 +00:00
ANPENDING *p = pendings + --pendingcnt;
if (p->w)
{
p->w->pending = 0;
p->w->cb (p->w, p->events);
}
}
}
static void
2007-10-31 20:46:44 +00:00
timers_reify (void)
{
2007-10-30 23:10:33 +00:00
while (timercnt && timers [0]->at <= now)
{
struct ev_timer *w = timers [0];
2007-10-30 23:10:33 +00:00
/* first reschedule or stop timer */
if (w->repeat)
{
2007-10-31 09:23:17 +00:00
w->at = now + w->repeat;
assert (("timer timeout in the past, negative repeat?", w->at > now));
downheap ((WT *)timers, timercnt, 0);
}
else
2007-11-01 06:48:49 +00:00
ev_timer_stop (w); /* nonrepeating: stop timer */
event ((W)w, EV_TIMEOUT);
2007-10-31 09:23:17 +00:00
}
}
static void
2007-10-31 20:46:44 +00:00
periodics_reify (void)
2007-10-31 09:23:17 +00:00
{
while (periodiccnt && periodics [0]->at <= ev_now)
{
struct ev_periodic *w = periodics [0];
/* first reschedule or stop timer */
if (w->interval)
2007-10-30 23:10:33 +00:00
{
2007-10-31 09:23:17 +00:00
w->at += floor ((ev_now - w->at) / w->interval + 1.) * w->interval;
assert (("periodic timeout in the past, negative interval?", w->at > ev_now));
downheap ((WT *)periodics, periodiccnt, 0);
2007-10-30 23:10:33 +00:00
}
2007-10-31 09:23:17 +00:00
else
2007-11-01 06:48:49 +00:00
ev_periodic_stop (w); /* nonrepeating: stop timer */
event ((W)w, EV_TIMEOUT);
}
}
2007-10-31 09:23:17 +00:00
static void
2007-10-31 10:50:05 +00:00
periodics_reschedule (ev_tstamp diff)
2007-10-31 09:23:17 +00:00
{
int i;
2007-10-31 10:50:05 +00:00
/* adjust periodics after time jump */
2007-10-31 09:23:17 +00:00
for (i = 0; i < periodiccnt; ++i)
{
struct ev_periodic *w = periodics [i];
if (w->interval)
{
ev_tstamp diff = ceil ((ev_now - w->at) / w->interval) * w->interval;
if (fabs (diff) >= 1e-4)
{
2007-11-01 06:48:49 +00:00
ev_periodic_stop (w);
ev_periodic_start (w);
2007-10-31 09:23:17 +00:00
i = 0; /* restart loop, inefficient, but time jumps should be rare */
}
}
}
}
2007-10-30 23:10:33 +00:00
static void
2007-10-31 20:46:44 +00:00
time_update (void)
2007-10-30 23:10:33 +00:00
{
int i;
2007-10-31 09:23:17 +00:00
2007-10-30 23:10:33 +00:00
ev_now = ev_time ();
if (have_monotonic)
{
ev_tstamp odiff = diff;
2007-10-31 09:23:17 +00:00
for (i = 4; --i; ) /* loop a few times, before making important decisions */
2007-10-30 23:10:33 +00:00
{
now = get_clock ();
diff = ev_now - now;
if (fabs (odiff - diff) < MIN_TIMEJUMP)
return; /* all is well */
ev_now = ev_time ();
}
2007-10-31 10:50:05 +00:00
periodics_reschedule (diff - odiff);
/* no timer adjustment, as the monotonic clock doesn't jump */
2007-10-30 23:10:33 +00:00
}
else
{
if (now > ev_now || now < ev_now - MAX_BLOCKTIME - MIN_TIMEJUMP)
2007-10-31 10:50:05 +00:00
{
periodics_reschedule (ev_now - now);
/* adjust timers. this is easy, as the offset is the same for all */
for (i = 0; i < timercnt; ++i)
timers [i]->at += diff;
}
2007-10-30 23:10:33 +00:00
now = ev_now;
}
}
int ev_loop_done;
2007-10-30 23:10:33 +00:00
void ev_loop (int flags)
{
double block;
2007-10-31 21:50:15 +00:00
ev_loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) ? 1 : 0;
do
{
2007-10-31 18:28:00 +00:00
/* queue check watchers (and execute them) */
2007-10-31 18:37:38 +00:00
if (preparecnt)
2007-10-31 18:28:00 +00:00
{
queue_events ((W *)prepares, preparecnt, EV_PREPARE);
call_pending ();
}
/* update fd-related kernel structures */
2007-10-30 23:54:38 +00:00
fd_reify ();
/* calculate blocking time */
2007-10-31 09:23:17 +00:00
2007-10-31 18:37:38 +00:00
/* we only need this for !monotonic clockor timers, but as we basically
always have timers, we just calculate it always */
2007-10-31 09:23:17 +00:00
ev_now = ev_time ();
if (flags & EVLOOP_NONBLOCK || idlecnt)
block = 0.;
else
{
2007-10-30 23:10:33 +00:00
block = MAX_BLOCKTIME;
2007-10-31 09:23:17 +00:00
if (timercnt)
2007-10-30 23:10:33 +00:00
{
2007-10-31 11:52:12 +00:00
ev_tstamp to = timers [0]->at - (have_monotonic ? get_clock () : ev_now) + method_fudge;
2007-10-30 23:10:33 +00:00
if (block > to) block = to;
}
2007-10-31 09:23:17 +00:00
if (periodiccnt)
2007-10-30 23:10:33 +00:00
{
2007-10-31 09:23:17 +00:00
ev_tstamp to = periodics [0]->at - ev_now + method_fudge;
2007-10-30 23:10:33 +00:00
if (block > to) block = to;
}
if (block < 0.) block = 0.;
}
method_poll (block);
2007-10-30 23:10:33 +00:00
/* update ev_now, do magic */
time_update ();
/* queue pending timers and reschedule them */
2007-10-31 18:28:00 +00:00
timers_reify (); /* relative timers called last */
periodics_reify (); /* absolute timers called first */
/* queue idle watchers unless io or timers are pending */
if (!pendingcnt)
queue_events ((W *)idles, idlecnt, EV_IDLE);
2007-10-31 18:28:00 +00:00
/* queue check watchers, to be executed first */
if (checkcnt)
queue_events ((W *)checks, checkcnt, EV_CHECK);
call_pending ();
}
while (!ev_loop_done);
2007-10-31 10:50:05 +00:00
if (ev_loop_done != 2)
ev_loop_done = 0;
}
2007-10-31 00:32:33 +00:00
/*****************************************************************************/
static void
wlist_add (WL *head, WL elem)
{
elem->next = *head;
*head = elem;
}
static void
wlist_del (WL *head, WL elem)
{
while (*head)
{
if (*head == elem)
{
*head = elem->next;
return;
}
head = &(*head)->next;
}
}
2007-10-31 13:57:34 +00:00
static void
ev_clear (W w)
{
if (w->pending)
{
pendings [w->pending - 1].w = 0;
w->pending = 0;
}
}
static void
ev_start (W w, int active)
{
w->active = active;
}
static void
ev_stop (W w)
{
w->active = 0;
}
2007-10-31 00:32:33 +00:00
/*****************************************************************************/
void
2007-11-01 06:48:49 +00:00
ev_io_start (struct ev_io *w)
{
if (ev_is_active (w))
return;
int fd = w->fd;
ev_start ((W)w, 1);
array_needsize (anfds, anfdmax, fd + 1, anfds_init);
wlist_add ((WL *)&anfds[fd].head, (WL)w);
2007-10-31 22:16:36 +00:00
fd_change (fd);
}
void
2007-11-01 06:48:49 +00:00
ev_io_stop (struct ev_io *w)
{
2007-10-31 13:57:34 +00:00
ev_clear ((W)w);
if (!ev_is_active (w))
return;
wlist_del ((WL *)&anfds[w->fd].head, (WL)w);
ev_stop ((W)w);
2007-10-31 22:16:36 +00:00
fd_change (w->fd);
}
void
2007-11-01 06:48:49 +00:00
ev_timer_start (struct ev_timer *w)
{
if (ev_is_active (w))
return;
2007-10-31 09:23:17 +00:00
w->at += now;
2007-10-31 10:50:05 +00:00
assert (("timer repeat value less than zero not allowed", w->repeat >= 0.));
2007-10-31 09:23:17 +00:00
ev_start ((W)w, ++timercnt);
array_needsize (timers, timermax, timercnt, );
timers [timercnt - 1] = w;
upheap ((WT *)timers, timercnt - 1);
}
void
2007-11-01 06:48:49 +00:00
ev_timer_stop (struct ev_timer *w)
{
2007-10-31 13:57:34 +00:00
ev_clear ((W)w);
if (!ev_is_active (w))
return;
2007-10-31 09:23:17 +00:00
if (w->active < timercnt--)
2007-10-30 21:42:12 +00:00
{
2007-10-31 09:23:17 +00:00
timers [w->active - 1] = timers [timercnt];
downheap ((WT *)timers, timercnt, w->active - 1);
2007-10-30 23:10:33 +00:00
}
2007-10-31 09:23:17 +00:00
2007-10-31 11:52:12 +00:00
w->at = w->repeat;
2007-10-31 09:23:17 +00:00
ev_stop ((W)w);
}
2007-10-31 11:52:12 +00:00
void
2007-11-01 06:48:49 +00:00
ev_timer_again (struct ev_timer *w)
2007-10-31 11:52:12 +00:00
{
if (ev_is_active (w))
{
if (w->repeat)
{
w->at = now + w->repeat;
downheap ((WT *)timers, timercnt, w->active - 1);
}
else
2007-11-01 06:48:49 +00:00
ev_timer_stop (w);
2007-10-31 11:52:12 +00:00
}
else if (w->repeat)
2007-11-01 06:48:49 +00:00