GRPC Core 0.10.0.0

- Main Page
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros 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 /* Time support.
37 We use gpr_timespec, which is analogous to struct timespec. On some
38 machines, absolute times may be in local time. */
39
40 #include <grpc/support/port_platform.h>
41 #include <stddef.h>
42 #include <time.h>
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48 /* The clocks we support. */
49 typedef enum {
50 /* Monotonic clock. Epoch undefined. Always moves forwards. */
51 GPR_CLOCK_MONOTONIC = 0,
52 /* Realtime clock. May jump forwards or backwards. Settable by
53 the system administrator. Has its epoch at 0:00:00 UTC 1 Jan 1970. */
54 GPR_CLOCK_REALTIME,
55 /* Unmeasurable clock type: no base, created by taking the difference
56 between two times */
57 GPR_TIMESPAN
58 } gpr_clock_type;
59
60 typedef struct gpr_timespec {
61 time_t tv_sec;
62 int tv_nsec;
65 gpr_clock_type clock_type;
66 } gpr_timespec;
67
68 /* Time constants. */
69 gpr_timespec gpr_time_0(gpr_clock_type type); /* The zero time interval. */
70 gpr_timespec gpr_inf_future(gpr_clock_type type); /* The far future */
71 gpr_timespec gpr_inf_past(gpr_clock_type type); /* The far past. */
72
73 #define GPR_MS_PER_SEC 1000
74 #define GPR_US_PER_SEC 1000000
75 #define GPR_NS_PER_SEC 1000000000
76 #define GPR_NS_PER_MS 1000000
77 #define GPR_NS_PER_US 1000
78 #define GPR_US_PER_MS 1000
79
80 /* initialize time subsystem */
81 void gpr_time_init(void);
82
83 /* Return the current time measured from the given clocks epoch. */
84 gpr_timespec gpr_now(gpr_clock_type clock);
85
86 /* Convert a timespec from one clock to another */
87 gpr_timespec gpr_convert_clock_type(gpr_timespec t, gpr_clock_type target_clock);
88
89 /* Return -ve, 0, or +ve according to whether a < b, a == b, or a > b
90 respectively. */
91 int gpr_time_cmp(gpr_timespec a, gpr_timespec b);
92
93 gpr_timespec gpr_time_max(gpr_timespec a, gpr_timespec b);
94 gpr_timespec gpr_time_min(gpr_timespec a, gpr_timespec b);
95
96 /* Add and subtract times. Calculations saturate at infinities. */
97 gpr_timespec gpr_time_add(gpr_timespec a, gpr_timespec b);
98 gpr_timespec gpr_time_sub(gpr_timespec a, gpr_timespec b);
99
100 /* Return a timespec representing a given number of time units. LONG_MIN is
101 interpreted as gpr_inf_past, and LONG_MAX as gpr_inf_future. */
102 gpr_timespec gpr_time_from_micros(long x, gpr_clock_type clock_type);
103 gpr_timespec gpr_time_from_nanos(long x, gpr_clock_type clock_type);
104 gpr_timespec gpr_time_from_millis(long x, gpr_clock_type clock_type);
105 gpr_timespec gpr_time_from_seconds(long x, gpr_clock_type clock_type);
106 gpr_timespec gpr_time_from_minutes(long x, gpr_clock_type clock_type);
107 gpr_timespec gpr_time_from_hours(long x, gpr_clock_type clock_type);
108
109 gpr_int32 gpr_time_to_millis(gpr_timespec timespec);
110
111 /* Return 1 if two times are equal or within threshold of each other,
112 0 otherwise */
113 int gpr_time_similar(gpr_timespec a, gpr_timespec b, gpr_timespec threshold);
114
115 /* Sleep until at least 'until' - an absolute timeout */
116 void gpr_sleep_until(gpr_timespec until);
117
118 double gpr_timespec_to_micros(gpr_timespec t);
119
120 #ifdef __cplusplus
121 }
122 #endif
123
124 #endif /* GRPC_SUPPORT_TIME_H */
port_platform.h
gpr_time_max
gpr_timespec gpr_time_max(gpr_timespec a, gpr_timespec b)
gpr_timespec::tv_sec
time_t tv_sec
Definition: time.h:61
GPR_CLOCK_REALTIME
Definition: time.h:54
time.h
gpr_time_from_millis
gpr_timespec gpr_time_from_millis(long x, gpr_clock_type clock_type)
gpr_inf_future
gpr_timespec gpr_inf_future(gpr_clock_type type)
gpr_inf_past
gpr_timespec gpr_inf_past(gpr_clock_type type)
gpr_time_from_hours
gpr_timespec gpr_time_from_hours(long x, gpr_clock_type clock_type)
gpr_time_min
gpr_timespec gpr_time_min(gpr_timespec a, gpr_timespec b)
gpr_timespec::clock_type
gpr_clock_type clock_type
Against which clock was this time measured? (or GPR_TIMESPAN if this is a relative time meaure) ...
Definition: time.h:65
gpr_time_from_nanos
gpr_timespec gpr_time_from_nanos(long x, gpr_clock_type clock_type)
GPR_CLOCK_MONOTONIC
Definition: time.h:51
gpr_convert_clock_type
gpr_timespec gpr_convert_clock_type(gpr_timespec t, gpr_clock_type target_clock)
gpr_time_sub
gpr_timespec gpr_time_sub(gpr_timespec a, gpr_timespec b)
gpr_time_cmp
int gpr_time_cmp(gpr_timespec a, gpr_timespec b)
gpr_timespec::tv_nsec
int tv_nsec
Definition: time.h:62
gpr_time_init
void gpr_time_init(void)
gpr_time_0
gpr_timespec gpr_time_0(gpr_clock_type type)
gpr_time_similar
int gpr_time_similar(gpr_timespec a, gpr_timespec b, gpr_timespec threshold)
gpr_time_add
gpr_timespec gpr_time_add(gpr_timespec a, gpr_timespec b)
GPR_TIMESPAN
Definition: time.h:57
gpr_time_to_millis
gpr_int32 gpr_time_to_millis(gpr_timespec timespec)
gpr_time_from_minutes
gpr_timespec gpr_time_from_minutes(long x, gpr_clock_type clock_type)
gpr_int32
int32_t gpr_int32
Definition: port_platform.h:305
gpr_timespec
struct gpr_timespec gpr_timespec
gpr_clock_type
gpr_clock_type
Definition: time.h:49
gpr_now
gpr_timespec gpr_now(gpr_clock_type clock)
gpr_timespec
Definition: time.h:60
gpr_timespec_to_micros
double gpr_timespec_to_micros(gpr_timespec t)
gpr_time_from_micros
gpr_timespec gpr_time_from_micros(long x, gpr_clock_type clock_type)
gpr_sleep_until
void gpr_sleep_until(gpr_timespec until)
gpr_time_from_seconds
gpr_timespec gpr_time_from_seconds(long x, gpr_clock_type clock_type)