From 2b226adf60eac113e6c2780aa551c775e72511d6 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Thu, 11 Jan 2018 16:11:35 -0800 Subject: Remove alarm from core, implement in C++ layer only --- include/grpc++/alarm.h | 51 ++++++++++++++------------------------------------ 1 file changed, 14 insertions(+), 37 deletions(-) (limited to 'include/grpc++') diff --git a/include/grpc++/alarm.h b/include/grpc++/alarm.h index b43425e224..4660b04cfa 100644 --- a/include/grpc++/alarm.h +++ b/include/grpc++/alarm.h @@ -28,17 +28,20 @@ #include #include -struct grpc_alarm; - namespace grpc { -class CompletionQueue; +namespace internal { +class AlarmImpl; +} /// A thin wrapper around \a grpc_alarm (see / \a / src/core/surface/alarm.h). class Alarm : private GrpcLibraryCodegen { public: /// Create an unset completion queue alarm - Alarm() : tag_(nullptr), alarm_(grpc_alarm_create(nullptr)) {} + Alarm(); + + /// Destroy the given completion queue alarm, cancelling it in the process. + ~Alarm(); /// DEPRECATED: Create and set a completion queue alarm instance associated to /// \a cq. @@ -48,10 +51,8 @@ class Alarm : private GrpcLibraryCodegen { /// 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(nullptr)) { - grpc_alarm_set(alarm_, cq->cq(), TimePoint(deadline).raw_time(), - static_cast(&tag_), nullptr); + Alarm(CompletionQueue* cq, const T& deadline, void* tag) : Alarm() { + SetInternal(cq, TimePoint(deadline).raw_time(), tag); } /// Trigger an alarm instance on completion queue \a cq at the specified time. @@ -60,9 +61,7 @@ class Alarm : private GrpcLibraryCodegen { /// event's success bit will be true, false otherwise (ie, upon cancellation). template void Set(CompletionQueue* cq, const T& deadline, void* tag) { - tag_.Set(tag); - grpc_alarm_set(alarm_, cq->cq(), TimePoint(deadline).raw_time(), - static_cast(&tag_), nullptr); + SetInternal(cq, TimePoint(deadline).raw_time(), tag); } /// Alarms aren't copyable. @@ -70,43 +69,21 @@ class Alarm : private GrpcLibraryCodegen { Alarm& operator=(const Alarm&) = delete; /// Alarms are movable. - Alarm(Alarm&& rhs) : tag_(rhs.tag_), alarm_(rhs.alarm_) { - rhs.alarm_ = nullptr; - } + Alarm(Alarm&& rhs) : alarm_(rhs.alarm_) { rhs.alarm_ = nullptr; } Alarm& operator=(Alarm&& rhs) { - tag_ = rhs.tag_; alarm_ = rhs.alarm_; rhs.alarm_ = nullptr; return *this; } - /// Destroy the given completion queue alarm, cancelling it in the process. - ~Alarm() { - if (alarm_ != nullptr) grpc_alarm_destroy(alarm_, nullptr); - } - /// Cancel a completion queue alarm. Calling this function over an alarm that /// has already fired has no effect. - void Cancel() { - if (alarm_ != nullptr) grpc_alarm_cancel(alarm_, nullptr); - } + void Cancel(); private: - class AlarmEntry : public internal::CompletionQueueTag { - public: - AlarmEntry(void* tag) : tag_(tag) {} - void Set(void* tag) { tag_ = tag; } - bool FinalizeResult(void** tag, bool* status) override { - *tag = tag_; - return true; - } - - private: - void* tag_; - }; + void SetInternal(CompletionQueue* cq, gpr_timespec deadline, void* tag); - AlarmEntry tag_; - grpc_alarm* alarm_; // owned + internal::AlarmImpl* alarm_; }; } // namespace grpc -- cgit v1.2.3