2 * Copyright (c) 2011 Nicira Networks.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include "poll-loop.h"
24 /* Returns the number of milliseconds until 'timer' expires. */
26 timer_msecs_until_expired(const struct timer *timer)
29 case LLONG_MAX: return LLONG_MAX;
30 case LLONG_MIN: return 0;
31 default: return timer->t - time_msec();
35 /* Causes poll_block() to wake when 'timer' expires. */
37 timer_wait(const struct timer *timer)
39 if (timer->t < LLONG_MAX) {
40 poll_timer_wait_until(timer->t);
44 /* Returns the time at which 'timer' was set with 'duration'. Infinite timers
45 * were enabled at time LLONG_MAX. Manually expired timers were enabled at
48 timer_enabled_at(const struct timer *timer, long long int duration)
51 case LLONG_MAX: return LLONG_MAX;
52 case LLONG_MIN: return LLONG_MIN;
53 default: return timer->t - duration;