From 0160873273be3fb502f05d4349e074422f4addcb Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Mon, 22 Feb 2016 17:49:45 -0800 Subject: [PATCH] PR comments addressed --- include/grpc++/alarm.h | 4 ++++ src/core/surface/alarm.c | 5 +++-- src/cpp/common/alarm.cc | 3 --- test/cpp/common/alarm_cpp_test.cc | 17 +++++++++++++++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/include/grpc++/alarm.h b/include/grpc++/alarm.h index 66904deb48..59988b8732 100644 --- a/include/grpc++/alarm.h +++ b/include/grpc++/alarm.h @@ -56,6 +56,10 @@ 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). + /// \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), 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 index 8af17597ef..0c96be20da 100644 --- a/src/cpp/common/alarm.cc +++ b/src/cpp/common/alarm.cc @@ -35,10 +35,7 @@ namespace grpc { -static internal::GrpcLibraryInitializer g_gli_initializer; - Alarm::~Alarm() { - g_gli_initializer.summon(); grpc_alarm_destroy(alarm_); } diff --git a/test/cpp/common/alarm_cpp_test.cc b/test/cpp/common/alarm_cpp_test.cc index 4745ef14ec..874c452fa9 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, Cancellation) { CompletionQueue cq; void* junk = reinterpret_cast(1618033);