Skip to content

Commit

Permalink
lib: Add and use io_loop_run_get_wait_time()
Browse files Browse the repository at this point in the history
This is going to be called just before running an ioloop iteration.
The next commit improves its behavior.
  • Loading branch information
sirainen committed Aug 22, 2018
1 parent f0981da commit 673e0aa
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/lib/ioloop-epoll.c
Expand Up @@ -175,7 +175,7 @@ void io_loop_handler_run_internal(struct ioloop *ioloop)
i_assert(ctx != NULL);

/* get the time left for next timeout task */
msecs = io_loop_get_wait_time(ioloop, &tv);
msecs = io_loop_run_get_wait_time(ioloop, &tv);

events = array_get_modifiable(&ctx->events, &events_count);
if (ioloop->io_files != NULL && events_count > ctx->deleted_count) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ioloop-kqueue.c
Expand Up @@ -119,7 +119,7 @@ void io_loop_handler_run_internal(struct ioloop *ioloop)
int ret, i, msecs;

/* get the time left for next timeout task */
msecs = io_loop_get_wait_time(ioloop, &tv);
msecs = io_loop_run_get_wait_time(ioloop, &tv);
ts.tv_sec = tv.tv_sec;
ts.tv_nsec = tv.tv_usec * 1000;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/ioloop-poll.c
Expand Up @@ -151,7 +151,7 @@ void io_loop_handler_run_internal(struct ioloop *ioloop)
bool call;

/* get the time left for next timeout task */
msecs = io_loop_get_wait_time(ioloop, &tv);
msecs = io_loop_run_get_wait_time(ioloop, &tv);
#ifdef _AIX
if (msecs > 1000) {
/* AIX seems to check IO_POLL_ERRORs only at the beginning of
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ioloop-private.h
Expand Up @@ -102,7 +102,7 @@ struct ioloop_context {
ARRAY(struct ioloop_context_callback) callbacks;
};

int io_loop_get_wait_time(struct ioloop *ioloop, struct timeval *tv_r);
int io_loop_run_get_wait_time(struct ioloop *ioloop, struct timeval *tv_r);
void io_loop_handle_timeouts(struct ioloop *ioloop);
void io_loop_call_io(struct io *io);

Expand Down
2 changes: 1 addition & 1 deletion src/lib/ioloop-select.c
Expand Up @@ -111,7 +111,7 @@ void io_loop_handler_run_internal(struct ioloop *ioloop)
int ret;

/* get the time left for next timeout task */
io_loop_get_wait_time(ioloop, &tv);
io_loop_run_get_wait_time(ioloop, &tv);

memcpy(&ctx->tmp_read_fds, &ctx->read_fds, sizeof(fd_set));
memcpy(&ctx->tmp_write_fds, &ctx->write_fds, sizeof(fd_set));
Expand Down
7 changes: 6 additions & 1 deletion src/lib/ioloop.c
Expand Up @@ -470,7 +470,7 @@ static int timeout_get_wait_time(struct timeout *timeout, struct timeval *tv_r,
return ret;
}

int io_loop_get_wait_time(struct ioloop *ioloop, struct timeval *tv_r)
static int io_loop_get_wait_time(struct ioloop *ioloop, struct timeval *tv_r)
{
struct timeval tv_now;
struct priorityq_item *item;
Expand Down Expand Up @@ -512,6 +512,11 @@ int io_loop_get_wait_time(struct ioloop *ioloop, struct timeval *tv_r)
return msecs;
}

int io_loop_run_get_wait_time(struct ioloop *ioloop, struct timeval *tv_r)
{
return io_loop_get_wait_time(ioloop, tv_r);
}

static int timeout_cmp(const void *p1, const void *p2)
{
const struct timeout *to1 = p1, *to2 = p2;
Expand Down

0 comments on commit 673e0aa

Please sign in to comment.