GRPC Core  43.0.0
time.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_SUPPORT_TIME_H
20 #define GRPC_SUPPORT_TIME_H
21 
22 #include <stddef.h>
23 #include <time.h>
24 
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
32 typedef enum {
45 
48 typedef struct gpr_timespec {
49  int64_t tv_sec;
50  int32_t tv_nsec;
54 } gpr_timespec;
55 
63 
64 #define GPR_MS_PER_SEC 1000
65 #define GPR_US_PER_SEC 1000000
66 #define GPR_NS_PER_SEC 1000000000
67 #define GPR_NS_PER_MS 1000000
68 #define GPR_NS_PER_US 1000
69 #define GPR_US_PER_MS 1000
70 
72 GPRAPI void gpr_time_init(void);
73 
76 
79  gpr_clock_type clock_type);
80 
84 
87 
91 
100 
101 GPRAPI int32_t gpr_time_to_millis(gpr_timespec timespec);
102 
106  gpr_timespec threshold);
107 
110 
112 
113 #ifdef __cplusplus
114 }
115 #endif
116 
117 #endif /* GRPC_SUPPORT_TIME_H */
gpr_timespec::tv_nsec
int32_t tv_nsec
Definition: time.h:50
gpr_timespec::tv_sec
int64_t tv_sec
Definition: time.h:49
gpr_time_from_millis
GPRAPI gpr_timespec gpr_time_from_millis(int64_t ms, gpr_clock_type clock_type)
gpr_time_from_nanos
GPRAPI gpr_timespec gpr_time_from_nanos(int64_t ns, gpr_clock_type clock_type)
gpr_time_from_micros
GPRAPI gpr_timespec gpr_time_from_micros(int64_t us, gpr_clock_type clock_type)
Return a timespec representing a given number of time units.
gpr_timespec
struct gpr_timespec gpr_timespec
Analogous to struct timespec.
gpr_sleep_until
GPRAPI void gpr_sleep_until(gpr_timespec until)
Sleep until at least 'until' - an absolute timeout.
gpr_time_from_seconds
GPRAPI gpr_timespec gpr_time_from_seconds(int64_t s, gpr_clock_type clock_type)
GPR_CLOCK_MONOTONIC
@ GPR_CLOCK_MONOTONIC
Monotonic clock.
Definition: time.h:34
gpr_time_min
GPRAPI gpr_timespec gpr_time_min(gpr_timespec a, gpr_timespec b)
gpr_time_from_minutes
GPRAPI gpr_timespec gpr_time_from_minutes(int64_t m, gpr_clock_type clock_type)
gpr_time_similar
GPRAPI int gpr_time_similar(gpr_timespec a, gpr_timespec b, gpr_timespec threshold)
Return 1 if two times are equal or within threshold of each other, 0 otherwise.
gpr_time_add
GPRAPI gpr_timespec gpr_time_add(gpr_timespec a, gpr_timespec b)
Add and subtract times.
gpr_time_from_hours
GPRAPI gpr_timespec gpr_time_from_hours(int64_t h, gpr_clock_type clock_type)
gpr_timespec_to_micros
GPRAPI double gpr_timespec_to_micros(gpr_timespec t)
gpr_time_max
GPRAPI gpr_timespec gpr_time_max(gpr_timespec a, gpr_timespec b)
gpr_time_to_millis
GPRAPI int32_t gpr_time_to_millis(gpr_timespec timespec)
gpr_inf_future
GPRAPI gpr_timespec gpr_inf_future(gpr_clock_type type)
The far future.
time.h
GPRAPI
#define GPRAPI
Definition: port_platform.h:721
gpr_time_0
GPRAPI gpr_timespec gpr_time_0(gpr_clock_type type)
Time constants.
gpr_time_init
GPRAPI void gpr_time_init(void)
initialize time subsystem
gpr_clock_type
gpr_clock_type
The clocks we support.
Definition: time.h:32
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 measure)
Definition: time.h:53
GPR_CLOCK_PRECISE
@ GPR_CLOCK_PRECISE
CPU cycle time obtained by rdtsc instruction on x86 platforms.
Definition: time.h:40
GPR_TIMESPAN
@ GPR_TIMESPAN
Unmeasurable clock type: no base, created by taking the difference between two times.
Definition: time.h:43
gpr_inf_past
GPRAPI gpr_timespec gpr_inf_past(gpr_clock_type type)
The far past.
gpr_now
GPRAPI gpr_timespec gpr_now(gpr_clock_type clock)
Return the current time measured from the given clocks epoch.
GPR_CLOCK_REALTIME
@ GPR_CLOCK_REALTIME
Realtime clock.
Definition: time.h:37
gpr_time_sub
GPRAPI gpr_timespec gpr_time_sub(gpr_timespec a, gpr_timespec b)
gpr_timespec
Analogous to struct timespec.
Definition: time.h:48
gpr_convert_clock_type
GPRAPI gpr_timespec gpr_convert_clock_type(gpr_timespec t, gpr_clock_type clock_type)
Convert a timespec from one clock to another.
gpr_time_cmp
GPRAPI int gpr_time_cmp(gpr_timespec a, gpr_timespec b)
Return -ve, 0, or +ve according to whether a < b, a == b, or a > b respectively.
port_platform.h