GRPC Core  18.0.0
completion_queue.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015-2016 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_CORE_LIB_SURFACE_COMPLETION_QUEUE_H
20 #define GRPC_CORE_LIB_SURFACE_COMPLETION_QUEUE_H
21 
22 /* Internal API for completion queues */
23 
25 
26 #include <grpc/grpc.h>
27 
31 
32 /* These trace flags default to 1. The corresponding lines are only traced
33  if grpc_api_trace is also truthy */
38 
39 typedef struct grpc_cq_completion {
42 
44  void* tag;
47  void (*done)(void* done_arg, struct grpc_cq_completion* c);
48  void* done_arg;
50  uintptr_t next;
52 
53 #ifndef NDEBUG
54 void grpc_cq_internal_ref(grpc_completion_queue* cq, const char* reason,
55  const char* file, int line);
56 void grpc_cq_internal_unref(grpc_completion_queue* cq, const char* reason,
57  const char* file, int line);
58 #define GRPC_CQ_INTERNAL_REF(cq, reason) \
59  grpc_cq_internal_ref(cq, reason, __FILE__, __LINE__)
60 #define GRPC_CQ_INTERNAL_UNREF(cq, reason) \
61  grpc_cq_internal_unref(cq, reason, __FILE__, __LINE__)
62 #else
65 #define GRPC_CQ_INTERNAL_REF(cq, reason) grpc_cq_internal_ref(cq)
66 #define GRPC_CQ_INTERNAL_UNREF(cq, reason) grpc_cq_internal_unref(cq)
67 #endif
68 
69 /* Initializes global variables used by completion queues */
70 void grpc_cq_global_init();
71 
72 /* Flag that an operation is beginning: the completion channel will not finish
73  shutdown until a corrensponding grpc_cq_end_* call is made.
74  \a tag is currently used only in debug builds. Return true on success, and
75  false if completion_queue has been shutdown. */
77 
78 /* Queue a GRPC_OP_COMPLETED operation; tag must correspond to the tag passed to
79  grpc_cq_begin_op */
82  void (*done)(void* done_arg, grpc_cq_completion* storage),
83  void* done_arg, grpc_cq_completion* storage,
84  bool internal = false);
85 
87 
89 
91 
93 
95  grpc_cq_completion_type completion_type, grpc_cq_polling_type polling_type,
96  grpc_completion_queue_functor* shutdown_callback);
97 
98 #endif /* GRPC_CORE_LIB_SURFACE_COMPLETION_QUEUE_H */
Definition: trace.h:61
void grpc_cq_internal_ref(grpc_completion_queue *cq, const char *reason, const char *file, int line)
Definition: completion_queue.cc:592
bool grpc_cq_begin_op(grpc_completion_queue *cq, void *tag)
Definition: completion_queue.cc:670
grpc_core::TraceFlag grpc_cq_pluck_trace
struct grpc_cq_completion grpc_cq_completion
grpc_pollset * grpc_cq_pollset(grpc_completion_queue *cq)
Definition: completion_queue.cc:1432
grpc_cq_completion_type grpc_get_cq_completion_type(grpc_completion_queue *cq)
Definition: completion_queue.cc:579
bool grpc_cq_can_listen(grpc_completion_queue *cq)
Definition: completion_queue.cc:1436
grpc_completion_queue * grpc_completion_queue_create_internal(grpc_cq_completion_type completion_type, grpc_cq_polling_type polling_type, grpc_completion_queue_functor *shutdown_callback)
Definition: completion_queue.cc:512
void grpc_cq_end_op(grpc_completion_queue *cq, void *tag, grpc_error_handle error, void(*done)(void *done_arg, grpc_cq_completion *storage), void *done_arg, grpc_cq_completion *storage, bool internal=false)
Definition: completion_queue.cc:895
void grpc_cq_global_init()
Definition: completion_queue.cc:442
void grpc_cq_internal_unref(grpc_completion_queue *cq, const char *reason, const char *file, int line)
Definition: completion_queue.cc:609
grpc_core::DebugOnlyTraceFlag grpc_trace_cq_refcount
grpc_core::TraceFlag grpc_trace_operation_failures
grpc_core::DebugOnlyTraceFlag grpc_trace_pending_tags
int grpc_get_cq_poll_num(grpc_completion_queue *cq)
Definition: completion_queue.cc:583
grpc_cq_completion_type
Specifies the type of APIs to use to pop events from the completion queue.
Definition: grpc_types.h:742
grpc_cq_polling_type
Completion queues internally MAY maintain a set of file descriptors in a structure called 'pollset'.
Definition: grpc_types.h:724
grpc_error_handle error
Definition: lame_client.cc:54
Specifies an interface class to be used as a tag for callback-based completion queues.
Definition: grpc_types.h:757
Definition: completion_queue.cc:339
Definition: completion_queue.h:39
uintptr_t next
next pointer; low bit is used to indicate success or not
Definition: completion_queue.h:50
void * done_arg
Definition: completion_queue.h:48
void(* done)(void *done_arg, struct grpc_cq_completion *c)
done callback - called when this queue element is no longer needed by the completion queue
Definition: completion_queue.h:47
grpc_core::ManualConstructor< grpc_core::MultiProducerSingleConsumerQueue > node
Definition: completion_queue.h:41
void * tag
user supplied tag
Definition: completion_queue.h:44
Definition: error_internal.h:41
Definition: pollset_custom.cc:40