Merge pull request #5293 from dgquintas/alarm_cpp

Made Alarm's constructor a template for deadline
pull/5427/head
Vijay Pai 9 years ago
commit 544b98fca3
  1. 2
      BUILD
  2. 2
      Makefile
  3. 1
      build.yaml
  4. 17
      include/grpc++/alarm.h
  5. 5
      src/core/surface/alarm.c
  6. 51
      src/cpp/common/alarm.cc
  7. 17
      test/cpp/common/alarm_cpp_test.cc
  8. 1
      tools/doxygen/Doxyfile.c++.internal
  9. 2
      tools/run_tests/sources_and_headers.json
  10. 2
      vsprojects/vcxproj/grpc++/grpc++.vcxproj
  11. 3
      vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters
  12. 2
      vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj
  13. 3
      vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters

@ -818,7 +818,6 @@ cc_library(
"src/cpp/client/credentials.cc", "src/cpp/client/credentials.cc",
"src/cpp/client/generic_stub.cc", "src/cpp/client/generic_stub.cc",
"src/cpp/client/insecure_credentials.cc", "src/cpp/client/insecure_credentials.cc",
"src/cpp/common/alarm.cc",
"src/cpp/common/call.cc", "src/cpp/common/call.cc",
"src/cpp/common/channel_arguments.cc", "src/cpp/common/channel_arguments.cc",
"src/cpp/common/completion_queue.cc", "src/cpp/common/completion_queue.cc",
@ -942,7 +941,6 @@ cc_library(
"src/cpp/client/credentials.cc", "src/cpp/client/credentials.cc",
"src/cpp/client/generic_stub.cc", "src/cpp/client/generic_stub.cc",
"src/cpp/client/insecure_credentials.cc", "src/cpp/client/insecure_credentials.cc",
"src/cpp/common/alarm.cc",
"src/cpp/common/call.cc", "src/cpp/common/call.cc",
"src/cpp/common/channel_arguments.cc", "src/cpp/common/channel_arguments.cc",
"src/cpp/common/completion_queue.cc", "src/cpp/common/completion_queue.cc",

@ -2990,7 +2990,6 @@ LIBGRPC++_SRC = \
src/cpp/client/credentials.cc \ src/cpp/client/credentials.cc \
src/cpp/client/generic_stub.cc \ src/cpp/client/generic_stub.cc \
src/cpp/client/insecure_credentials.cc \ src/cpp/client/insecure_credentials.cc \
src/cpp/common/alarm.cc \
src/cpp/common/call.cc \ src/cpp/common/call.cc \
src/cpp/common/channel_arguments.cc \ src/cpp/common/channel_arguments.cc \
src/cpp/common/completion_queue.cc \ src/cpp/common/completion_queue.cc \
@ -3271,7 +3270,6 @@ LIBGRPC++_UNSECURE_SRC = \
src/cpp/client/credentials.cc \ src/cpp/client/credentials.cc \
src/cpp/client/generic_stub.cc \ src/cpp/client/generic_stub.cc \
src/cpp/client/insecure_credentials.cc \ src/cpp/client/insecure_credentials.cc \
src/cpp/common/alarm.cc \
src/cpp/common/call.cc \ src/cpp/common/call.cc \
src/cpp/common/channel_arguments.cc \ src/cpp/common/channel_arguments.cc \
src/cpp/common/completion_queue.cc \ src/cpp/common/completion_queue.cc \

@ -184,7 +184,6 @@ filegroups:
- src/cpp/client/credentials.cc - src/cpp/client/credentials.cc
- src/cpp/client/generic_stub.cc - src/cpp/client/generic_stub.cc
- src/cpp/client/insecure_credentials.cc - src/cpp/client/insecure_credentials.cc
- src/cpp/common/alarm.cc
- src/cpp/common/call.cc - src/cpp/common/call.cc
- src/cpp/common/channel_arguments.cc - src/cpp/common/channel_arguments.cc
- src/cpp/common/completion_queue.cc - src/cpp/common/completion_queue.cc

@ -36,9 +36,12 @@
#ifndef GRPCXX_ALARM_H #ifndef GRPCXX_ALARM_H
#define 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/completion_queue_tag.h>
#include <grpc++/impl/codegen/grpc_library.h> #include <grpc++/impl/codegen/grpc_library.h>
#include <grpc++/impl/codegen/time.h> #include <grpc++/impl/codegen/time.h>
#include <grpc++/impl/grpc_library.h>
#include <grpc/grpc.h>
struct grpc_alarm; 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), /// 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 /// 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). /// 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. /// 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 /// Cancel a completion queue alarm. Calling this function over an alarm that
/// has already fired has no effect. /// has already fired has no effect.
void Cancel(); void Cancel() { grpc_alarm_cancel(alarm_); }
private: private:
class AlarmEntry : public CompletionQueueTag { class AlarmEntry : public CompletionQueueTag {

@ -64,8 +64,9 @@ grpc_alarm *grpc_alarm_create(grpc_completion_queue *cq, gpr_timespec deadline,
alarm->tag = tag; alarm->tag = tag;
grpc_cq_begin_op(cq, tag); grpc_cq_begin_op(cq, tag);
grpc_timer_init(&exec_ctx, &alarm->alarm, deadline, alarm_cb, alarm, grpc_timer_init(&exec_ctx, &alarm->alarm,
gpr_now(GPR_CLOCK_MONOTONIC)); gpr_convert_clock_type(deadline, GPR_CLOCK_MONOTONIC),
alarm_cb, alarm, gpr_now(GPR_CLOCK_MONOTONIC));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
return alarm; return alarm;
} }

@ -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

@ -55,6 +55,23 @@ TEST(AlarmTest, RegularExpiry) {
EXPECT_EQ(junk, output_tag); 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) { TEST(AlarmTest, ZeroExpiry) {
CompletionQueue cq; CompletionQueue cq;
void* junk = reinterpret_cast<void*>(1618033); void* junk = reinterpret_cast<void*>(1618033);

@ -854,7 +854,6 @@ src/cpp/client/create_channel_internal.cc \
src/cpp/client/credentials.cc \ src/cpp/client/credentials.cc \
src/cpp/client/generic_stub.cc \ src/cpp/client/generic_stub.cc \
src/cpp/client/insecure_credentials.cc \ src/cpp/client/insecure_credentials.cc \
src/cpp/common/alarm.cc \
src/cpp/common/call.cc \ src/cpp/common/call.cc \
src/cpp/common/channel_arguments.cc \ src/cpp/common/channel_arguments.cc \
src/cpp/common/completion_queue.cc \ src/cpp/common/completion_queue.cc \

@ -5041,7 +5041,6 @@
"src/cpp/client/secure_credentials.cc", "src/cpp/client/secure_credentials.cc",
"src/cpp/client/secure_credentials.h", "src/cpp/client/secure_credentials.h",
"src/cpp/codegen/grpc_library.cc", "src/cpp/codegen/grpc_library.cc",
"src/cpp/common/alarm.cc",
"src/cpp/common/auth_property_iterator.cc", "src/cpp/common/auth_property_iterator.cc",
"src/cpp/common/call.cc", "src/cpp/common/call.cc",
"src/cpp/common/channel_arguments.cc", "src/cpp/common/channel_arguments.cc",
@ -5300,7 +5299,6 @@
"src/cpp/client/generic_stub.cc", "src/cpp/client/generic_stub.cc",
"src/cpp/client/insecure_credentials.cc", "src/cpp/client/insecure_credentials.cc",
"src/cpp/codegen/grpc_library.cc", "src/cpp/codegen/grpc_library.cc",
"src/cpp/common/alarm.cc",
"src/cpp/common/call.cc", "src/cpp/common/call.cc",
"src/cpp/common/channel_arguments.cc", "src/cpp/common/channel_arguments.cc",
"src/cpp/common/completion_queue.cc", "src/cpp/common/completion_queue.cc",

@ -369,8 +369,6 @@
</ClCompile> </ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\cpp\client\insecure_credentials.cc"> <ClCompile Include="$(SolutionDir)\..\src\cpp\client\insecure_credentials.cc">
</ClCompile> </ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\cpp\common\alarm.cc">
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\cpp\common\call.cc"> <ClCompile Include="$(SolutionDir)\..\src\cpp\common\call.cc">
</ClCompile> </ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\cpp\common\channel_arguments.cc"> <ClCompile Include="$(SolutionDir)\..\src\cpp\common\channel_arguments.cc">

@ -40,9 +40,6 @@
<ClCompile Include="$(SolutionDir)\..\src\cpp\client\insecure_credentials.cc"> <ClCompile Include="$(SolutionDir)\..\src\cpp\client\insecure_credentials.cc">
<Filter>src\cpp\client</Filter> <Filter>src\cpp\client</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\cpp\common\alarm.cc">
<Filter>src\cpp\common</Filter>
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\cpp\common\call.cc"> <ClCompile Include="$(SolutionDir)\..\src\cpp\common\call.cc">
<Filter>src\cpp\common</Filter> <Filter>src\cpp\common</Filter>
</ClCompile> </ClCompile>

@ -356,8 +356,6 @@
</ClCompile> </ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\cpp\client\insecure_credentials.cc"> <ClCompile Include="$(SolutionDir)\..\src\cpp\client\insecure_credentials.cc">
</ClCompile> </ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\cpp\common\alarm.cc">
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\cpp\common\call.cc"> <ClCompile Include="$(SolutionDir)\..\src\cpp\common\call.cc">
</ClCompile> </ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\cpp\common\channel_arguments.cc"> <ClCompile Include="$(SolutionDir)\..\src\cpp\common\channel_arguments.cc">

@ -25,9 +25,6 @@
<ClCompile Include="$(SolutionDir)\..\src\cpp\client\insecure_credentials.cc"> <ClCompile Include="$(SolutionDir)\..\src\cpp\client\insecure_credentials.cc">
<Filter>src\cpp\client</Filter> <Filter>src\cpp\client</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\cpp\common\alarm.cc">
<Filter>src\cpp\common</Filter>
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\cpp\common\call.cc"> <ClCompile Include="$(SolutionDir)\..\src\cpp\common\call.cc">
<Filter>src\cpp\common</Filter> <Filter>src\cpp\common</Filter>
</ClCompile> </ClCompile>

Loading…
Cancel
Save