aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/grpc++
diff options
context:
space:
mode:
authorGravatar Vijay Pai <vpai@google.com>2018-01-11 16:11:35 -0800
committerGravatar Vijay Pai <vpai@google.com>2018-01-21 21:03:56 -0800
commit2b226adf60eac113e6c2780aa551c775e72511d6 (patch)
treeea3172e769594f379a093ea0f23b2927a47e4254 /include/grpc++
parent5b48dc737151464c1d863df6e4318ff3d766ddbc (diff)
Remove alarm from core, implement in C++ layer only
Diffstat (limited to 'include/grpc++')
-rw-r--r--include/grpc++/alarm.h51
1 files changed, 14 insertions, 37 deletions
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 <grpc++/impl/grpc_library.h>
#include <grpc/grpc.h>
-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 <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 +61,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 +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