diff options
Diffstat (limited to 'include/grpc++/alarm.h')
-rw-r--r-- | include/grpc++/alarm.h | 17 |
1 files changed, 14 insertions, 3 deletions
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 { |