diff options
author | David Garcia Quintas <dgq@google.com> | 2017-06-19 13:57:32 -0700 |
---|---|---|
committer | David Garcia Quintas <dgq@google.com> | 2017-06-20 15:42:56 -0700 |
commit | e48949f0b44d0f8755cbbc3837a2b591867cd0bf (patch) | |
tree | de0331371464117f7f7e090309445fb4193c4c27 /include | |
parent | 070a8eeb281a2659501a60b1bbc86798fcb652c4 (diff) |
Make grpc::Alarm non-copyable
Diffstat (limited to 'include')
-rw-r--r-- | include/grpc++/alarm.h | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/include/grpc++/alarm.h b/include/grpc++/alarm.h index bd000cf4f7..ed8dacbc94 100644 --- a/include/grpc++/alarm.h +++ b/include/grpc++/alarm.h @@ -52,8 +52,25 @@ class Alarm : private GrpcLibraryCodegen { alarm_(grpc_alarm_create(cq->cq(), TimePoint<T>(deadline).raw_time(), static_cast<void*>(&tag_))) {} + /// Alarms aren't copyable. + Alarm(const Alarm&) = delete; + Alarm& operator=(const Alarm&) = delete; + + /// Alarms are movable. + Alarm(Alarm&& rhs) : tag_(rhs.tag_), 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() { grpc_alarm_destroy(alarm_); } + ~Alarm() { + if (alarm_ != nullptr) grpc_alarm_destroy(alarm_); + } /// Cancel a completion queue alarm. Calling this function over an alarm that /// has already fired has no effect. @@ -73,7 +90,7 @@ class Alarm : private GrpcLibraryCodegen { }; AlarmEntry tag_; - grpc_alarm* const alarm_; // owned + grpc_alarm* alarm_; // owned }; } // namespace grpc |