diff options
author | Vijay Pai <vpai@google.com> | 2018-02-02 08:44:20 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-02 08:44:20 -0800 |
commit | e5b0a504167fbc6277d034709aa29ea07fa09a00 (patch) | |
tree | 6c6c080621452edeaead91ba48a1857810829699 /include | |
parent | ba92ab53bf50c8e12c90e62bbd0935008d696fa3 (diff) | |
parent | 392e2131e17bd2a028d5b91b7a99aee26bbfbf19 (diff) |
Merge pull request #14015 from vjpai/alarm
Remove alarm from core, implement in C++ layer only
Diffstat (limited to 'include')
-rw-r--r-- | include/grpc++/alarm.h | 49 | ||||
-rw-r--r-- | include/grpc/grpc.h | 19 |
2 files changed, 11 insertions, 57 deletions
diff --git a/include/grpc++/alarm.h b/include/grpc++/alarm.h index b43425e224..37d4189201 100644 --- a/include/grpc++/alarm.h +++ b/include/grpc++/alarm.h @@ -28,17 +28,16 @@ #include <grpc++/impl/grpc_library.h> #include <grpc/grpc.h> -struct grpc_alarm; - namespace grpc { -class CompletionQueue; - /// 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 +47,8 @@ class Alarm : private GrpcLibraryCodegen { /// 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(nullptr)) { - grpc_alarm_set(alarm_, cq->cq(), TimePoint<T>(deadline).raw_time(), - static_cast<void*>(&tag_), nullptr); + Alarm(CompletionQueue* cq, const T& deadline, void* tag) : Alarm() { + SetInternal(cq, TimePoint<T>(deadline).raw_time(), tag); } /// Trigger an alarm instance on completion queue \a cq at the specified time. @@ -60,9 +57,7 @@ class Alarm : private GrpcLibraryCodegen { /// event's success bit will be true, false otherwise (ie, upon cancellation). template <typename T> void Set(CompletionQueue* cq, const T& deadline, void* tag) { - tag_.Set(tag); - grpc_alarm_set(alarm_, cq->cq(), TimePoint<T>(deadline).raw_time(), - static_cast<void*>(&tag_), nullptr); + SetInternal(cq, TimePoint<T>(deadline).raw_time(), tag); } /// Alarms aren't copyable. @@ -70,43 +65,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::CompletionQueueTag* alarm_; }; } // namespace grpc diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index f083bc591e..47d749c728 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -160,25 +160,6 @@ GRPCAPI void grpc_completion_queue_thread_local_cache_init( GRPCAPI int grpc_completion_queue_thread_local_cache_flush( grpc_completion_queue* cq, void** tag, int* ok); -/** Create a completion queue alarm instance */ -GRPCAPI grpc_alarm* grpc_alarm_create(void* reserved); - -/** Set a completion queue alarm instance associated to \a cq. - * - * Once the alarm expires (at \a deadline) or it's cancelled (see \a - * grpc_alarm_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). */ -GRPCAPI void grpc_alarm_set(grpc_alarm* alarm, grpc_completion_queue* cq, - gpr_timespec deadline, void* tag, void* reserved); - -/** Cancel a completion queue alarm. Calling this function over an alarm that - * has already fired has no effect. */ -GRPCAPI void grpc_alarm_cancel(grpc_alarm* alarm, void* reserved); - -/** Destroy the given completion queue alarm, cancelling it in the process. */ -GRPCAPI void grpc_alarm_destroy(grpc_alarm* alarm, void* reserved); - /** Check the connectivity state of a channel. */ GRPCAPI grpc_connectivity_state grpc_channel_check_connectivity_state( grpc_channel* channel, int try_to_connect); |