aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/grpc++
diff options
context:
space:
mode:
authorGravatar Vijay Pai <vpai@google.com>2018-02-02 08:44:20 -0800
committerGravatar GitHub <noreply@github.com>2018-02-02 08:44:20 -0800
commite5b0a504167fbc6277d034709aa29ea07fa09a00 (patch)
tree6c6c080621452edeaead91ba48a1857810829699 /include/grpc++
parentba92ab53bf50c8e12c90e62bbd0935008d696fa3 (diff)
parent392e2131e17bd2a028d5b91b7a99aee26bbfbf19 (diff)
Merge pull request #14015 from vjpai/alarm
Remove alarm from core, implement in C++ layer only
Diffstat (limited to 'include/grpc++')
-rw-r--r--include/grpc++/alarm.h49
1 files changed, 11 insertions, 38 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