ioloop.c revision 20a3870db4f78717574ee94bca1512994391b2ab
/* Copyright (c) 2002-2008 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "ioloop-internal.h"
#include <unistd.h>
/* If time moves backwards more than this, kill ourself instead of sleeping. */
#define IOLOOP_MAX_TIME_BACKWARDS_SLEEP 5
time_t ioloop_time = 0;
struct timeval ioloop_timeval;
struct timezone ioloop_timezone;
{
}
}
{
else
/* if we got here from an I/O handler callback, make sure we
don't try to handle this one next. */
}
{
/* make sure the callback doesn't get called anymore.
kqueue code relies on this. */
else {
}
}
{
i_fatal("gettimeofday(): %m");
} else {
}
/* we don't want microsecond accuracy or this function will be
called all the time - millisecond is more than enough */
}
}
void *context)
{
NULL : &ioloop_timeval);
return timeout;
}
{
}
static void
{
/* if we came here from io_loop_handle_timeouts(),
next_run must be larger than tv_now or we could go to
infinite loop */
}
}
{
}
{
int ret;
i_fatal("gettimeofday(): %m");
} else {
}
}
/* round wait times up to next millisecond */
}
{
struct priorityq_item *item;
/* no timeouts. give it INT_MAX msecs. */
return INT_MAX;
}
}
{
int diff;
if (diff == 0)
return diff;
}
{
struct priorityq_item *item;
unsigned int t_id;
i_fatal("gettimeofday(): %m");
/* Don't bother comparing usecs. */
/* Note that this code is here only because this is the easiest
place to check for this. The I/O loop code itself could be
easily fixed to work with time moving backwards, but there's
really no point because there are a lot of other places
which may break in more or less bad ways, such as files'
timestamps moving backwards. */
if (diff > IOLOOP_MAX_TIME_BACKWARDS_SLEEP) {
i_fatal("Time just moved backwards by %ld seconds. "
"This might cause a lot of problems, "
"so I'll just kill myself now. "
(long)diff);
} else {
i_error("Time just moved backwards by %ld seconds. "
"I'll sleep now until we're back in present. "
(long)diff);
/* Sleep extra second to make sure usecs also grows. */
diff++;
/* don't use sleep()'s return value, because
it could get us to a long loop in case
interrupts just keep coming */
}
/* Try again. */
}
}
/* use tv_call to make sure we don't get to infinite loop in
case callbacks update ioloop_timeval. */
break;
/* update timeout's next_run and reposition it in the queue */
i_panic("Leaked a t_pop() call in timeout handler %p",
}
}
}
{
);
}
{
}
{
}
{
}
{
}
struct ioloop *io_loop_create(void)
{
/* initialize time */
i_fatal("gettimeofday(): %m");
return ioloop;
}
{
struct priorityq_item *item;
}
}
/* ->prev won't work unless loops are destroyed in create order */
}