]>
Commit | Line | Data |
---|---|---|
8650b075 | 1 | /* |
5453ae20 | 2 | * Copyright (c) 2011, 2013 Nicira, Inc. |
8650b075 EJ |
3 | * |
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: | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
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. | |
15 | */ | |
16 | ||
17 | #ifndef TIMER_H | |
18 | #define TIMER_H 1 | |
19 | ||
20 | #include <stdbool.h> | |
21 | ||
22 | #include "timeval.h" | |
f89ffb0e | 23 | #include "util.h" |
8650b075 EJ |
24 | |
25 | struct timer { | |
26 | long long int t; | |
27 | }; | |
28 | ||
29 | long long int timer_msecs_until_expired(const struct timer *); | |
5453ae20 | 30 | void timer_wait_at(const struct timer *, const char *where); |
8f3676cf | 31 | #define timer_wait(timer) timer_wait_at(timer, OVS_SOURCE_LOCATOR) |
8650b075 EJ |
32 | |
33 | /* Causes 'timer' to expire when 'duration' milliseconds have passed. | |
34 | * | |
35 | * May be used to initialize 'timer'. */ | |
36 | static inline void | |
37 | timer_set_duration(struct timer *timer, long long int duration) | |
38 | { | |
39 | timer->t = time_msec() + duration; | |
40 | } | |
41 | ||
42 | /* Causes 'timer' never to expire. | |
43 | * | |
44 | * May be used to initialize 'timer'. */ | |
45 | static inline void | |
46 | timer_set_infinite(struct timer *timer) | |
47 | { | |
48 | timer->t = LLONG_MAX; | |
49 | } | |
50 | ||
51 | /* Causes 'timer' to expire immediately. | |
52 | * | |
53 | * May be used to initialize 'timer'. */ | |
54 | static inline void | |
55 | timer_set_expired(struct timer *timer) | |
56 | { | |
57 | timer->t = LLONG_MIN; | |
58 | } | |
59 | ||
8650b075 EJ |
60 | /* True if 'timer' has expired. */ |
61 | static inline bool | |
62 | timer_expired(const struct timer *timer) | |
63 | { | |
e9e3173f | 64 | return time_msec() >= timer->t; |
8650b075 EJ |
65 | } |
66 | ||
67 | /* Returns ture if 'timer' will never expire. */ | |
68 | static inline bool | |
69 | timer_is_infinite(const struct timer *timer) | |
70 | { | |
71 | return timer->t == LLONG_MAX; | |
72 | } | |
73 | ||
74 | #endif /* timer.h */ |