diff options
-rw-r--r-- | BUILD | 2 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | build.yaml | 1 | ||||
-rw-r--r-- | include/grpc++/alarm.h | 17 | ||||
-rw-r--r-- | src/core/surface/alarm.c | 5 | ||||
-rw-r--r-- | src/cpp/common/alarm.cc | 51 | ||||
-rw-r--r-- | test/cpp/common/alarm_cpp_test.cc | 18 | ||||
-rw-r--r-- | tools/doxygen/Doxyfile.c++.internal | 1 | ||||
-rw-r--r-- | tools/run_tests/sources_and_headers.json | 2 | ||||
-rw-r--r-- | vsprojects/vcxproj/grpc++/grpc++.vcxproj | 2 | ||||
-rw-r--r-- | vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters | 3 | ||||
-rw-r--r-- | vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj | 2 | ||||
-rw-r--r-- | vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters | 3 |
13 files changed, 35 insertions, 74 deletions
@@ -795,7 +795,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", @@ -919,7 +918,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", @@ -2944,7 +2944,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 \ @@ -3225,7 +3224,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 4d76bab1e1..029afdc500 100644 --- a/build.yaml +++ b/build.yaml @@ -183,7 +183,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 9979c34e4f..3b8104d135 100644 --- a/include/grpc++/alarm.h +++ b/include/grpc++/alarm.h @@ -36,9 +36,12 @@ #ifndef GRPCXX_ALARM_H #define GRPCXX_ALARM_H +#include <grpc++/impl/codegen/completion_queue.h> #include <grpc++/impl/codegen/completion_queue_tag.h> #include <grpc++/impl/codegen/grpc_library.h> #include <grpc++/impl/codegen/time.h> +#include <grpc++/impl/grpc_library.h> +#include <grpc/grpc.h> 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 <typename T> + Alarm(CompletionQueue* cq, const T& deadline, void* tag) + : tag_(tag), + alarm_(grpc_alarm_create(cq->cq(), TimePoint<T>(deadline).raw_time(), + static_cast<void*>(&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 fb496f6c47..8169ede065 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 a289688768..0000000000 --- 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 <grpc++/alarm.h> -#include <grpc++/completion_queue.h> -#include <grpc++/impl/grpc_library.h> -#include <grpc/grpc.h> - -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<void*>(&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 5d7344046c..323b7c0fcf 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<void*>(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<void*>(1618033); @@ -85,6 +102,7 @@ TEST(AlarmTest, NegativeExpiry) { EXPECT_EQ(junk, output_tag); } + TEST(AlarmTest, Cancellation) { CompletionQueue cq; void* junk = reinterpret_cast<void*>(1618033); diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index d5e5df86f6..a285310847 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 e44a7bc79e..8666a36c9e 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -4132,7 +4132,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", @@ -4385,7 +4384,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 c62faf33e6..0b8c345196 100644 --- a/vsprojects/vcxproj/grpc++/grpc++.vcxproj +++ b/vsprojects/vcxproj/grpc++/grpc++.vcxproj @@ -369,8 +369,6 @@ </ClCompile> <ClCompile Include="$(SolutionDir)\..\src\cpp\client\insecure_credentials.cc"> </ClCompile> - <ClCompile Include="$(SolutionDir)\..\src\cpp\common\alarm.cc"> - </ClCompile> <ClCompile Include="$(SolutionDir)\..\src\cpp\common\call.cc"> </ClCompile> <ClCompile Include="$(SolutionDir)\..\src\cpp\common\channel_arguments.cc"> diff --git a/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters b/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters index 5f9350e76a..0f3dccf17c 100644 --- a/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters +++ b/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters @@ -40,9 +40,6 @@ <ClCompile Include="$(SolutionDir)\..\src\cpp\client\insecure_credentials.cc"> <Filter>src\cpp\client</Filter> </ClCompile> - <ClCompile Include="$(SolutionDir)\..\src\cpp\common\alarm.cc"> - <Filter>src\cpp\common</Filter> - </ClCompile> <ClCompile Include="$(SolutionDir)\..\src\cpp\common\call.cc"> <Filter>src\cpp\common</Filter> </ClCompile> diff --git a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj index fb4246580f..2dcadbaec0 100644 --- a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj +++ b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj @@ -356,8 +356,6 @@ </ClCompile> <ClCompile Include="$(SolutionDir)\..\src\cpp\client\insecure_credentials.cc"> </ClCompile> - <ClCompile Include="$(SolutionDir)\..\src\cpp\common\alarm.cc"> - </ClCompile> <ClCompile Include="$(SolutionDir)\..\src\cpp\common\call.cc"> </ClCompile> <ClCompile Include="$(SolutionDir)\..\src\cpp\common\channel_arguments.cc"> diff --git a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters index eeff7d3697..3572c651b6 100644 --- a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters +++ b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters @@ -25,9 +25,6 @@ <ClCompile Include="$(SolutionDir)\..\src\cpp\client\insecure_credentials.cc"> <Filter>src\cpp\client</Filter> </ClCompile> - <ClCompile Include="$(SolutionDir)\..\src\cpp\common\alarm.cc"> - <Filter>src\cpp\common</Filter> - </ClCompile> <ClCompile Include="$(SolutionDir)\..\src\cpp\common\call.cc"> <Filter>src\cpp\common</Filter> </ClCompile> |