-/* Copyright (c) 2008, 2009 Nicira Networks, Inc.
+/* Copyright (c) 2008, 2009, 2010 Nicira Networks, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
static void
scanner_wait(struct scanner *s)
{
- long long int now = time_msec();
- long long int expires = s->last_move + 750;
- if (now >= expires) {
- poll_immediate_wake();
- } else {
- poll_timer_wait(expires - now);
- }
-
+ poll_timer_wait_until(s->last_move + 750);
}
static void
refresh();
poll_fd_wait(STDIN_FILENO, POLLIN);
- poll_timer_wait(timeout - time_msec());
+ poll_timer_wait_until(timeout);
poll_block();
} while (time_msec() < timeout);
age_messages();
rconn_run_wait(rconn);
rconn_recv_wait(rconn);
- poll_timer_wait(timeout - time_msec());
+ poll_timer_wait_until(timeout);
poll_block();
}
}
refresh();
if (pos < min || pos > max) {
- poll_timer_wait(adjust - time_msec());
+ poll_timer_wait_until(adjust);
}
poll_fd_wait(STDIN_FILENO, POLLIN);
poll_block();
block_until(long long timeout)
{
while (timeout > time_msec()) {
- poll_timer_wait(timeout - time_msec());
+ poll_timer_wait_until(timeout);
poll_block();
}
drain_keyboard_buffer();
dhclient_wait(struct dhclient *cli)
{
if (cli->min_timeout != UINT_MAX) {
- time_t now = time_now();
- unsigned int wake = sat_add(cli->state_entered, cli->min_timeout);
- if (wake <= now) {
- poll_immediate_wake();
- } else {
- poll_timer_wait(sat_mul(sat_sub(wake, now), 1000));
- }
+ long long int wake = sat_add(cli->state_entered, cli->min_timeout);
+ poll_timer_wait_until(wake * 1000);
}
/* Reset timeout to 1 second. This will have no effect ordinarily, because
* dhclient_run() will typically set it back to a higher value. If,
static void
wait_timeout(long long int started)
{
- long long int now = time_msec();
- poll_timer_wait(10000 - (now - started));
+ poll_timer_wait_until(started + 10000);
}
void
{
if (!list_is_empty(&ml->lrus)) {
struct mac_entry *e = mac_entry_from_lru_node(ml->lrus.next);
- poll_timer_wait((e->expires - time_now()) * 1000);
+ poll_timer_wait_until(e->expires * 1000LL);
}
}
: msec);
}
+/* Causes the following call to poll_block() to wake up when the current time,
+ * as returned by time_msec(), reaches 'msec' or later. If 'msec' is earlier
+ * than the current time, the following call to poll_block() will not block at
+ * all.
+ *
+ * The timer registration is one-shot: only the following call to poll_block()
+ * is affected. The timer will need to be re-registered after poll_block() is
+ * called if it is to persist. */
+void
+poll_timer_wait_until(long long int msec)
+{
+ long long int now = time_msec();
+ poll_timer_wait__(msec <= now ? 0
+ : msec < now + INT_MAX ? msec - now
+ : INT_MAX);
+}
+
/* Causes the following call to poll_block() to wake up immediately, without
* blocking. */
void
/* Schedule events to wake up the following poll_block(). */
struct poll_waiter *poll_fd_wait(int fd, short int events);
void poll_timer_wait(long long int msec);
+void poll_timer_wait_until(long long int msec);
void poll_immediate_wake(void);
/* Wait until an event occurs. */
timeo = timeout(rc);
if (timeo != UINT_MAX) {
- unsigned int expires = sat_add(rc->state_entered, timeo);
- unsigned int remaining = sat_sub(expires, time_now());
- poll_timer_wait(sat_mul(remaining, 1000));
+ long long int expires = sat_add(rc->state_entered, timeo);
+ poll_timer_wait_until(expires * 1000);
}
if ((rc->state & (S_ACTIVE | S_IDLE)) && rc->txq.n) {
fail_open_wait(struct fail_open *fo)
{
if (fo->next_bogus_packet_in != LLONG_MAX) {
- poll_timer_wait(fo->next_bogus_packet_in - time_msec());
+ poll_timer_wait_until(fo->next_bogus_packet_in);
}
}
void
in_band_wait(struct in_band *in_band)
{
- time_t now = time_now();
- time_t wakeup
+ long long int wakeup
= MIN(in_band->next_remote_refresh, in_band->next_local_refresh);
- if (wakeup > now) {
- poll_timer_wait((wakeup - now) * 1000);
- } else {
- poll_immediate_wake();
- }
+ poll_timer_wait_until(wakeup * 1000);
}
/* ofproto has flushed all flows from the flow table and it is calling us back
ofproto_sflow_wait(struct ofproto_sflow *os)
{
if (ofproto_sflow_is_enabled(os)) {
- poll_timer_wait(os->next_tick * 1000 - time_msec());
+ poll_timer_wait_until(os->next_tick * 1000LL);
}
}
ofconn_wait(ofconn);
}
if (p->in_band) {
- poll_timer_wait(p->next_in_band_update - time_msec());
+ poll_timer_wait_until(p->next_in_band_update);
in_band_wait(p->in_band);
}
if (p->fail_open) {
VLOG_DBG_RL(&rl, "need revalidate in ofproto_wait_cb()");
poll_immediate_wake();
} else if (p->next_expiration != LLONG_MAX) {
- poll_timer_wait(p->next_expiration - time_msec());
+ poll_timer_wait_until(p->next_expiration);
}
for (i = 0; i < p->n_listeners; i++) {
pvconn_wait(p->listeners[i]);
}
if (deadline < LLONG_MAX) {
- poll_timer_wait(deadline - now);
+ poll_timer_wait_until(deadline);
}
}
}
for (j = 0; j < port->n_ifaces; j++) {
struct iface *iface = port->ifaces[j];
if (iface->delay_expires != LLONG_MAX) {
- poll_timer_wait(iface->delay_expires - time_msec());
+ poll_timer_wait_until(iface->delay_expires);
}
}
if (port->bond_fake_iface) {
- poll_timer_wait(port->bond_next_fake_iface_update - time_msec());
+ poll_timer_wait_until(port->bond_next_fake_iface_update);
}
}
}
poll_timer_wait(1000);
}
if (next_refresh != LLONG_MAX) {
- poll_timer_wait(next_refresh - time_msec());
+ poll_timer_wait_until(next_refresh);
}
}
}