time_cc.cc
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 #include <chrono>
20 #include <cstdint>
21 
23 #include <grpc/support/time.h>
24 #include <grpcpp/support/time.h>
25 
26 // IWYU pragma: no_include <ratio>
27 
28 using std::chrono::duration_cast;
29 using std::chrono::high_resolution_clock;
30 using std::chrono::nanoseconds;
32 using std::chrono::system_clock;
33 
34 namespace grpc {
35 
37  gpr_timespec* to) {
38  system_clock::duration deadline = from.time_since_epoch();
39  seconds secs = duration_cast<seconds>(deadline);
41  secs.count() >= gpr_inf_future(GPR_CLOCK_REALTIME).tv_sec ||
42  secs.count() < 0) {
44  return;
45  }
46  nanoseconds nsecs = duration_cast<nanoseconds>(deadline - secs);
47  to->tv_sec = static_cast<int64_t>(secs.count());
48  to->tv_nsec = static_cast<int32_t>(nsecs.count());
49  to->clock_type = GPR_CLOCK_REALTIME;
50 }
51 
53  gpr_timespec* to) {
54  high_resolution_clock::duration deadline = from.time_since_epoch();
55  seconds secs = duration_cast<seconds>(deadline);
57  secs.count() >= gpr_inf_future(GPR_CLOCK_REALTIME).tv_sec ||
58  secs.count() < 0) {
60  return;
61  }
62  nanoseconds nsecs = duration_cast<nanoseconds>(deadline - secs);
63  to->tv_sec = static_cast<int64_t>(secs.count());
64  to->tv_nsec = static_cast<int32_t>(nsecs.count());
65  to->clock_type = GPR_CLOCK_REALTIME;
66 }
67 
69  if (gpr_time_cmp(t, gpr_inf_future(t.clock_type)) == 0) {
71  }
74  tp += duration_cast<system_clock::time_point::duration>(seconds(t.tv_sec));
75  tp +=
76  duration_cast<system_clock::time_point::duration>(nanoseconds(t.tv_nsec));
77  return tp;
78 }
79 
80 } // namespace grpc
absl::time_internal::cctz::seconds
std::chrono::duration< std::int_fast64_t > seconds
Definition: abseil-cpp/absl/time/internal/cctz/include/cctz/time_zone.h:40
grpc
Definition: grpcpp/alarm.h:33
absl::time_internal::cctz::time_point
std::chrono::time_point< std::chrono::system_clock, D > time_point
Definition: abseil-cpp/absl/time/internal/cctz/include/cctz/time_zone.h:39
gpr_inf_future
GPRAPI gpr_timespec gpr_inf_future(gpr_clock_type type)
Definition: src/core/lib/gpr/time.cc:55
time.h
to
size_t to
Definition: abseil-cpp/absl/container/internal/layout_test.cc:1385
time.h
from
size_t from
Definition: abseil-cpp/absl/container/internal/layout_test.cc:1384
int64_t
signed __int64 int64_t
Definition: stdint-msvc2008.h:89
gpr_time_cmp
GPRAPI int gpr_time_cmp(gpr_timespec a, gpr_timespec b)
Definition: src/core/lib/gpr/time.cc:30
max
int max
Definition: bloaty/third_party/zlib/examples/enough.c:170
grpc::Timespec2Timepoint
std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t)
Definition: time_cc.cc:68
gpr_types.h
gpr_convert_clock_type
GPRAPI gpr_timespec gpr_convert_clock_type(gpr_timespec t, gpr_clock_type clock_type)
Definition: src/core/lib/gpr/time.cc:241
grpc::Timepoint2Timespec
void Timepoint2Timespec(const std::chrono::system_clock::time_point &from, gpr_timespec *to)
grpc::TimepointHR2Timespec
void TimepointHR2Timespec(const std::chrono::high_resolution_clock::time_point &from, gpr_timespec *to)
gpr_timespec
Definition: gpr_types.h:50
GPR_CLOCK_REALTIME
@ GPR_CLOCK_REALTIME
Definition: gpr_types.h:39
int32_t
signed int int32_t
Definition: stdint-msvc2008.h:77


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:37