GRPC Core  3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
time.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015, Google Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following disclaimer
14  * in the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of Google Inc. nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
33 
34 #ifndef GRPC_SUPPORT_TIME_H
35 #define GRPC_SUPPORT_TIME_H
36 
38 
39 #include <stddef.h>
40 #include <time.h>
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /* Time constants. */
48 gpr_time_0(gpr_clock_type type); /* The zero time interval. */
49 GPRAPI gpr_timespec gpr_inf_future(gpr_clock_type type); /* The far future */
50 GPRAPI gpr_timespec gpr_inf_past(gpr_clock_type type); /* The far past. */
51 
52 #define GPR_MS_PER_SEC 1000
53 #define GPR_US_PER_SEC 1000000
54 #define GPR_NS_PER_SEC 1000000000
55 #define GPR_NS_PER_MS 1000000
56 #define GPR_NS_PER_US 1000
57 #define GPR_US_PER_MS 1000
58 
59 /* initialize time subsystem */
60 GPRAPI void gpr_time_init(void);
61 
62 /* Return the current time measured from the given clocks epoch. */
64 
65 /* Convert a timespec from one clock to another */
67  gpr_clock_type target_clock);
68 
69 /* Return -ve, 0, or +ve according to whether a < b, a == b, or a > b
70  respectively. */
72 
75 
76 /* Add and subtract times. Calculations saturate at infinities. */
79 
80 /* Return a timespec representing a given number of time units. INT64_MIN is
81  interpreted as gpr_inf_past, and INT64_MAX as gpr_inf_future. */
88 
89 GPRAPI int32_t gpr_time_to_millis(gpr_timespec timespec);
90 
91 /* Return 1 if two times are equal or within threshold of each other,
92  0 otherwise */
94  gpr_timespec threshold);
95 
96 /* Sleep until at least 'until' - an absolute timeout */
98 
100 
101 #ifdef __cplusplus
102 }
103 #endif
104 
105 #endif /* GRPC_SUPPORT_TIME_H */
GPRAPI gpr_timespec gpr_time_from_nanos(int64_t x, gpr_clock_type clock_type)
GPRAPI gpr_timespec gpr_time_sub(gpr_timespec a, gpr_timespec b)
GPRAPI gpr_timespec gpr_time_max(gpr_timespec a, gpr_timespec b)
GPRAPI gpr_timespec gpr_inf_past(gpr_clock_type type)
GPRAPI gpr_timespec gpr_convert_clock_type(gpr_timespec t, gpr_clock_type target_clock)
GPRAPI gpr_timespec gpr_time_from_millis(int64_t x, gpr_clock_type clock_type)
#define GPRAPI
Definition: port_platform.h:410
GPRAPI gpr_timespec gpr_time_from_minutes(int64_t x, gpr_clock_type clock_type)
GPRAPI void gpr_time_init(void)
GPRAPI gpr_timespec gpr_time_from_seconds(int64_t x, gpr_clock_type clock_type)
GPRAPI int gpr_time_cmp(gpr_timespec a, gpr_timespec b)
GPRAPI gpr_timespec gpr_time_add(gpr_timespec a, gpr_timespec b)
GPRAPI gpr_timespec gpr_time_min(gpr_timespec a, gpr_timespec b)
GPRAPI int32_t gpr_time_to_millis(gpr_timespec timespec)
GPRAPI gpr_timespec gpr_inf_future(gpr_clock_type type)
GPRAPI gpr_timespec gpr_time_0(gpr_clock_type type)
GPRAPI gpr_timespec gpr_time_from_micros(int64_t x, gpr_clock_type clock_type)
Definition: gpr_types.h:63
gpr_clock_type
Definition: gpr_types.h:47
GPRAPI gpr_timespec gpr_time_from_hours(int64_t x, gpr_clock_type clock_type)
GPRAPI void gpr_sleep_until(gpr_timespec until)
GPRAPI int gpr_time_similar(gpr_timespec a, gpr_timespec b, gpr_timespec threshold)
GPRAPI gpr_timespec gpr_now(gpr_clock_type clock)
GPRAPI double gpr_timespec_to_micros(gpr_timespec t)