diff --git a/BUILD b/BUILD index 51eb446630b..0e9f37a0e3f 100644 --- a/BUILD +++ b/BUILD @@ -818,7 +818,6 @@ cc_library( "src/cpp/client/credentials.cc", "src/cpp/client/generic_stub.cc", "src/cpp/client/insecure_credentials.cc", - "src/cpp/common/alarm.cc", "src/cpp/common/call.cc", "src/cpp/common/channel_arguments.cc", "src/cpp/common/completion_queue.cc", @@ -942,7 +941,6 @@ cc_library( "src/cpp/client/credentials.cc", "src/cpp/client/generic_stub.cc", "src/cpp/client/insecure_credentials.cc", - "src/cpp/common/alarm.cc", "src/cpp/common/call.cc", "src/cpp/common/channel_arguments.cc", "src/cpp/common/completion_queue.cc", diff --git a/Makefile b/Makefile index 941827bf9c5..5be0d146afc 100644 --- a/Makefile +++ b/Makefile @@ -2990,7 +2990,6 @@ LIBGRPC++_SRC = \ src/cpp/client/credentials.cc \ src/cpp/client/generic_stub.cc \ src/cpp/client/insecure_credentials.cc \ - src/cpp/common/alarm.cc \ src/cpp/common/call.cc \ src/cpp/common/channel_arguments.cc \ src/cpp/common/completion_queue.cc \ @@ -3271,7 +3270,6 @@ LIBGRPC++_UNSECURE_SRC = \ src/cpp/client/credentials.cc \ src/cpp/client/generic_stub.cc \ src/cpp/client/insecure_credentials.cc \ - src/cpp/common/alarm.cc \ src/cpp/common/call.cc \ src/cpp/common/channel_arguments.cc \ src/cpp/common/completion_queue.cc \ diff --git a/build.yaml b/build.yaml index c4bbca6e2ce..a277539a054 100644 --- a/build.yaml +++ b/build.yaml @@ -184,7 +184,6 @@ filegroups: - src/cpp/client/credentials.cc - src/cpp/client/generic_stub.cc - src/cpp/client/insecure_credentials.cc - - src/cpp/common/alarm.cc - src/cpp/common/call.cc - src/cpp/common/channel_arguments.cc - src/cpp/common/completion_queue.cc diff --git a/include/grpc++/alarm.h b/include/grpc++/alarm.h index 9979c34e4f1..3b8104d1357 100644 --- a/include/grpc++/alarm.h +++ b/include/grpc++/alarm.h @@ -36,9 +36,12 @@ #ifndef GRPCXX_ALARM_H #define GRPCXX_ALARM_H +#include #include #include #include +#include +#include struct grpc_alarm; @@ -54,14 +57,22 @@ class Alarm : private GrpcLibrary { /// Once the alarm expires (at \a deadline) or it's cancelled (see \a Cancel), /// an event with tag \a tag will be added to \a cq. If the alarm expired, the /// event's success bit will be true, false otherwise (ie, upon cancellation). - Alarm(CompletionQueue* cq, gpr_timespec deadline, void* tag); + /// \internal We rely on the presence of \a cq for grpc initialization. If \a + /// cq were ever to be removed, a reference to a static + /// internal::GrpcLibraryInitializer instance would need to be introduced + /// here. \endinternal. + template + Alarm(CompletionQueue* cq, const T& deadline, void* tag) + : tag_(tag), + alarm_(grpc_alarm_create(cq->cq(), TimePoint(deadline).raw_time(), + static_cast(&tag_))) {} /// Destroy the given completion queue alarm, cancelling it in the process. - ~Alarm(); + ~Alarm() { grpc_alarm_destroy(alarm_); } /// Cancel a completion queue alarm. Calling this function over an alarm that /// has already fired has no effect. - void Cancel(); + void Cancel() { grpc_alarm_cancel(alarm_); } private: class AlarmEntry : public CompletionQueueTag { diff --git a/src/core/surface/alarm.c b/src/core/surface/alarm.c index fb496f6c474..8169ede0655 100644 --- a/src/core/surface/alarm.c +++ b/src/core/surface/alarm.c @@ -64,8 +64,9 @@ grpc_alarm *grpc_alarm_create(grpc_completion_queue *cq, gpr_timespec deadline, alarm->tag = tag; grpc_cq_begin_op(cq, tag); - grpc_timer_init(&exec_ctx, &alarm->alarm, deadline, alarm_cb, alarm, - gpr_now(GPR_CLOCK_MONOTONIC)); + grpc_timer_init(&exec_ctx, &alarm->alarm, + gpr_convert_clock_type(deadline, GPR_CLOCK_MONOTONIC), + alarm_cb, alarm, gpr_now(GPR_CLOCK_MONOTONIC)); grpc_exec_ctx_finish(&exec_ctx); return alarm; } diff --git a/src/cpp/common/alarm.cc b/src/cpp/common/alarm.cc deleted file mode 100644 index a2896887682..00000000000 --- a/src/cpp/common/alarm.cc +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2015-2016, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include -#include -#include -#include - -namespace grpc { - -static internal::GrpcLibraryInitializer g_gli_initializer; -Alarm::Alarm(CompletionQueue* cq, gpr_timespec deadline, void* tag) - : tag_(tag), - alarm_(grpc_alarm_create(cq->cq(), deadline, static_cast(&tag_))) { - g_gli_initializer.summon(); -} - -Alarm::~Alarm() { grpc_alarm_destroy(alarm_); } - -void Alarm::Cancel() { grpc_alarm_cancel(alarm_); } - -} // namespace grpc diff --git a/test/cpp/common/alarm_cpp_test.cc b/test/cpp/common/alarm_cpp_test.cc index 5d7344046ce..d4381c05158 100644 --- a/test/cpp/common/alarm_cpp_test.cc +++ b/test/cpp/common/alarm_cpp_test.cc @@ -55,6 +55,23 @@ TEST(AlarmTest, RegularExpiry) { EXPECT_EQ(junk, output_tag); } +TEST(AlarmTest, RegularExpiryChrono) { + CompletionQueue cq; + void* junk = reinterpret_cast(1618033); + std::chrono::system_clock::time_point one_sec_deadline = + std::chrono::system_clock::now() + std::chrono::seconds(1); + Alarm alarm(&cq, one_sec_deadline, junk); + + void* output_tag; + bool ok; + const CompletionQueue::NextStatus status = cq.AsyncNext( + (void**)&output_tag, &ok, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(2)); + + EXPECT_EQ(status, CompletionQueue::GOT_EVENT); + EXPECT_TRUE(ok); + EXPECT_EQ(junk, output_tag); +} + TEST(AlarmTest, ZeroExpiry) { CompletionQueue cq; void* junk = reinterpret_cast(1618033); diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index d5e5df86f64..a2853108476 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -854,7 +854,6 @@ src/cpp/client/create_channel_internal.cc \ src/cpp/client/credentials.cc \ src/cpp/client/generic_stub.cc \ src/cpp/client/insecure_credentials.cc \ -src/cpp/common/alarm.cc \ src/cpp/common/call.cc \ src/cpp/common/channel_arguments.cc \ src/cpp/common/completion_queue.cc \ diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index 6b70f091ebe..0c7a6c7b5f3 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -5041,7 +5041,6 @@ "src/cpp/client/secure_credentials.cc", "src/cpp/client/secure_credentials.h", "src/cpp/codegen/grpc_library.cc", - "src/cpp/common/alarm.cc", "src/cpp/common/auth_property_iterator.cc", "src/cpp/common/call.cc", "src/cpp/common/channel_arguments.cc", @@ -5300,7 +5299,6 @@ "src/cpp/client/generic_stub.cc", "src/cpp/client/insecure_credentials.cc", "src/cpp/codegen/grpc_library.cc", - "src/cpp/common/alarm.cc", "src/cpp/common/call.cc", "src/cpp/common/channel_arguments.cc", "src/cpp/common/completion_queue.cc", diff --git a/vsprojects/vcxproj/grpc++/grpc++.vcxproj b/vsprojects/vcxproj/grpc++/grpc++.vcxproj index c62faf33e6f..0b8c3451969 100644 --- a/vsprojects/vcxproj/grpc++/grpc++.vcxproj +++ b/vsprojects/vcxproj/grpc++/grpc++.vcxproj @@ -369,8 +369,6 @@ - - diff --git a/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters b/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters index 5f9350e76a0..0f3dccf17c5 100644 --- a/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters +++ b/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters @@ -40,9 +40,6 @@ src\cpp\client - - src\cpp\common - src\cpp\common diff --git a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj index fb4246580fd..2dcadbaec0c 100644 --- a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj +++ b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj @@ -356,8 +356,6 @@ - - diff --git a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters index eeff7d3697c..3572c651b6d 100644 --- a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters +++ b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters @@ -25,9 +25,6 @@ src\cpp\client - - src\cpp\common - src\cpp\common