Branch data Line data Source code
1 : : /*
2 : : * Copyright (c) 2011, 2013 Nicira, Inc.
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"
23 : : #include "util.h"
24 : :
25 : : struct timer {
26 : : long long int t;
27 : : };
28 : :
29 : : long long int timer_msecs_until_expired(const struct timer *);
30 : : void timer_wait_at(const struct timer *, const char *where);
31 : : #define timer_wait(timer) timer_wait_at(timer, OVS_SOURCE_LOCATOR)
32 : :
33 : : /* Causes 'timer' to expire when 'duration' milliseconds have passed.
34 : : *
35 : : * May be used to initialize 'timer'. */
36 : : static inline void
37 : 2040 : timer_set_duration(struct timer *timer, long long int duration)
38 : : {
39 : 2040 : timer->t = time_msec() + duration;
40 : 2040 : }
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 : 16 : timer_set_expired(struct timer *timer)
56 : : {
57 : 16 : timer->t = LLONG_MIN;
58 : 16 : }
59 : :
60 : : /* True if 'timer' has expired. */
61 : : static inline bool
62 : 24434 : timer_expired(const struct timer *timer)
63 : : {
64 : 24434 : return time_msec() >= timer->t;
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 */
|