aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/grpc++/impl/codegen/completion_queue.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/grpc++/impl/codegen/completion_queue.h')
-rw-r--r--include/grpc++/impl/codegen/completion_queue.h24
1 files changed, 22 insertions, 2 deletions
diff --git a/include/grpc++/impl/codegen/completion_queue.h b/include/grpc++/impl/codegen/completion_queue.h
index 29bc97fdf7..944f2c3919 100644
--- a/include/grpc++/impl/codegen/completion_queue.h
+++ b/include/grpc++/impl/codegen/completion_queue.h
@@ -52,6 +52,7 @@
#include <grpc++/impl/codegen/grpc_library.h>
#include <grpc++/impl/codegen/status.h>
#include <grpc++/impl/codegen/time.h>
+#include <grpc/impl/codegen/atm.h>
struct grpc_completion_queue;
@@ -101,6 +102,7 @@ class CompletionQueue : private GrpcLibraryCodegen {
/// instance.
CompletionQueue() {
cq_ = g_core_codegen_interface->grpc_completion_queue_create(nullptr);
+ InitialAvalanching(); // reserve this for the future shutdown
}
/// Wrap \a take, taking ownership of the instance.
@@ -151,7 +153,8 @@ class CompletionQueue : private GrpcLibraryCodegen {
/// Request the shutdown of the queue.
///
- /// \warning This method must be called at some point. Once invoked, \a Next
+ /// \warning This method must be called at some point if this completion queue
+ /// is accessed with Next or AsyncNext. Once invoked, \a Next
/// will start to return false and \a AsyncNext will return \a
/// NextStatus::SHUTDOWN. Only once either one of these methods does that
/// (that is, once the queue has been \em drained) can an instance of this
@@ -165,6 +168,21 @@ class CompletionQueue : private GrpcLibraryCodegen {
/// owership is performed.
grpc_completion_queue* cq() { return cq_; }
+ /// Manage state of avalanching operations : completion queue tags that
+ /// trigger other completion queue operations. The underlying core completion
+ /// queue should not really shutdown until all avalanching operations have
+ /// been finalized. Note that we maintain the requirement that an avalanche
+ /// registration must take place before CQ shutdown (which must be maintained
+ /// elsehwere)
+ void InitialAvalanching() {
+ gpr_atm_rel_store(&avalanches_in_flight_, static_cast<gpr_atm>(1));
+ }
+ void RegisterAvalanching() {
+ gpr_atm_no_barrier_fetch_add(&avalanches_in_flight_,
+ static_cast<gpr_atm>(1));
+ };
+ void CompleteAvalanching();
+
private:
// Friend synchronous wrappers so that they can access Pluck(), which is
// a semi-private API geared towards the synchronous implementation.
@@ -229,6 +247,8 @@ class CompletionQueue : private GrpcLibraryCodegen {
}
grpc_completion_queue* cq_; // owned
+
+ gpr_atm avalanches_in_flight_;
};
/// A specific type of completion queue used by the processing of notifications
@@ -240,7 +260,7 @@ class ServerCompletionQueue : public CompletionQueue {
private:
bool is_frequently_polled_;
friend class ServerBuilder;
- /// \param is_frequently_polled Informs the GPRC library about whether the
+ /// \param is_frequently_polled Informs the GRPC library about whether the
/// server completion queue would be actively polled (by calling Next() or
/// AsyncNext()). By default all server completion queues are assumed to be
/// frequently polled.