1 /*
2  * Copyright (c) 2008-2015 by Farsight Security, 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 NMSG_TIMESPEC_H
18 #define NMSG_TIMESPEC_H
19 
20 /*! \file nmsg/timespec.h
21  * \brief Sleeping and getting the current time.
22  */
23 
24 /**
25  * Get the current time.
26  *
27  * If available, clock_gettime() will be used to attempt to get the current
28  * real time. If unavailable, gettimeofday() will be used and scaled up to
29  * nanosecond precision.
30  *
31  * \param[out] ts current time.
32  */
33 void
34 nmsg_timespec_get(struct timespec *ts);
35 
36 /**
37  * Sleep.
38  *
39  * nanosleep() will be called, and reinvoked if interrupted.
40  *
41  * \param[in] ts duration to sleep.
42  */
43 void
44 nmsg_timespec_sleep(const struct timespec *ts);
45 
46 /**
47  * Add timespecs a and b, placing result in b.  (b = b + a).
48  *
49  * \param[in] a
50  * \param[in,out] b
51  */
52 void
53 nmsg_timespec_add(const struct timespec *a, struct timespec *b);
54 
55 /**
56  * Subtract timespec a from b, placing result in b.  (b = b - a).
57  *
58  * \param[in] a
59  * \param[in,out] b
60  */
61 void
62 nmsg_timespec_sub(const struct timespec *a, struct timespec *b);
63 
64 /**
65  * Convert timespec to floating point representation.
66  *
67  * \param[in] ts
68  *
69  * \return Floating point number of seconds.
70  */
71 double
72 nmsg_timespec_to_double(const struct timespec *ts);
73 
74 /**
75  * Convert floating point number of seconds to timespec.
76  *
77  * \param[in] seconds Floating point number of seconds.
78  * \param[out] ts
79  */
80 void
81 nmsg_timespec_from_double(double seconds, struct timespec *ts);
82 
83 #endif /* NMSG_TIMESPEC_H */
84