Skip to content
Snippets Groups Projects
Commit 7a4e5b42 authored by Sree Kuchibhotla's avatar Sree Kuchibhotla
Browse files

Completion queue creation API change (JUST API change. No functionality change)

parent a35d0e38
No related branches found
No related tags found
No related merge requests found
......@@ -93,9 +93,51 @@ GRPCAPI const char *grpc_version_string(void);
/** Return a string specifying what the 'g' in gRPC stands for */
GRPCAPI const char *grpc_g_stands_for(void);
/** Create a completion queue */
/** Specifies the type of APIs to use to pop events from the completion queue */
typedef enum {
/** Events are popped out by calling grpc_completion_queue_next() API ONLY */
GRPC_CQ_NEXT = 1,
/** Events are popped out by calling grpc_completion_queue_pluck() API ONLY*/
GRPC_CQ_PLUCK
} grpc_cq_completion_type;
/** Completion queues internally MAY maintain a set of file descriptors in a
structure called 'pollset'. This enum specifies if a completion queue has an
associated pollset and any restrictions on the type of file descriptors that
can be present in the pollset.
I/O progress can only be made when grpc_completion_queue_next() or
grpc_completion_queue_pluck() are called on the completion queue (unless the
grpc_cq_polling_type is NON_POLLING) and hence it is very important to
actively call these APIs */
typedef enum {
/** The completion queue will have an associated pollset and there is no
restriction on the type of file descriptors the pollset may contain */
DEFAULT_POLLING,
/** Similar to DEFAULT_POLLING except that the completion queues will not
contain any 'listening file descriptors' (i.e file descriptors used to
listen to incoming channels */
NON_LISTENING,
/** The completion queue will not have an associated pollset. Note that
grpc_completion_queue_next() or grpc_completion_queue_pluck() MUST still
be called to pop events from the completion queue; it is not required to
call them actively to make I/O progress */
NON_POLLING
} grpc_cq_polling_type;
/** Create a completion queue.
WARNING: This API is deprecated and will soon be deleted and replaced with
completion_queue_create_ex() */
GRPCAPI grpc_completion_queue *grpc_completion_queue_create(void *reserved);
/** Create a completion queue */
GRPCAPI grpc_completion_queue *grpc_completion_queue_create_ex(
grpc_cq_completion_type completion_type, grpc_cq_polling_type polling_type,
void *reserved);
/** Blocks until an event is available, the completion queue is being shut down,
or deadline is reached.
......
......@@ -64,6 +64,10 @@ typedef struct {
struct grpc_completion_queue {
/** owned by pollset */
gpr_mu *mu;
grpc_cq_completion_type completion_type;
grpc_cq_polling_type polling_type;
/** completed events */
grpc_cq_completion completed_head;
grpc_cq_completion *completed_tail;
......@@ -79,6 +83,7 @@ struct grpc_completion_queue {
int shutdown_called;
int is_server_cq;
/** Can the server cq accept incoming channels */
/* TODO: sreek - This will no longer be needed. Use polling_type set */
int is_non_listening_server_cq;
int num_pluckers;
plucker pluckers[GRPC_MAX_COMPLETION_QUEUE_PLUCKERS];
......@@ -110,7 +115,9 @@ int grpc_cq_event_timeout_trace;
static void on_pollset_shutdown_done(grpc_exec_ctx *exec_ctx, void *cc,
grpc_error *error);
grpc_completion_queue *grpc_completion_queue_create(void *reserved) {
grpc_completion_queue *grpc_completion_queue_create_ex(
grpc_cq_completion_type completion_type, grpc_cq_polling_type polling_type,
void *reserved) {
grpc_completion_queue *cc;
GPR_ASSERT(!reserved);
......@@ -148,6 +155,10 @@ grpc_completion_queue *grpc_completion_queue_create(void *reserved) {
return cc;
}
grpc_completion_queue *grpc_completion_queue_create(void *reserved) {
return grpc_completion_queue_create_ex(0, DEFAULT_POLLING, reserved);
}
#ifdef GRPC_CQ_REF_COUNT_DEBUG
void grpc_cq_internal_ref(grpc_completion_queue *cc, const char *reason,
const char *file, int line) {
......@@ -356,8 +367,9 @@ grpc_event grpc_completion_queue_next(grpc_completion_queue *cc,
"deadline=gpr_timespec { tv_sec: %" PRId64
", tv_nsec: %d, clock_type: %d }, "
"reserved=%p)",
5, (cc, deadline.tv_sec, deadline.tv_nsec, (int)deadline.clock_type,
reserved));
5,
(cc, deadline.tv_sec, deadline.tv_nsec, (int)deadline.clock_type,
reserved));
GPR_ASSERT(!reserved);
dump_pending_tags(cc);
......@@ -524,8 +536,9 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cc, void *tag,
"deadline=gpr_timespec { tv_sec: %" PRId64
", tv_nsec: %d, clock_type: %d }, "
"reserved=%p)",
6, (cc, tag, deadline.tv_sec, deadline.tv_nsec,
(int)deadline.clock_type, reserved));
6,
(cc, tag, deadline.tv_sec, deadline.tv_nsec, (int)deadline.clock_type,
reserved));
}
GPR_ASSERT(!reserved);
......@@ -681,10 +694,14 @@ grpc_completion_queue *grpc_cq_from_pollset(grpc_pollset *ps) {
}
void grpc_cq_mark_non_listening_server_cq(grpc_completion_queue *cc) {
/* TODO: sreek - use cc->polling_type field here and add a validation check
(i.e grpc_cq_mark_non_listening_server_cq can only be called on a cc whose
polling_type is set to NON_LISTENING */
cc->is_non_listening_server_cq = 1;
}
bool grpc_cq_is_non_listening_server_cq(grpc_completion_queue *cc) {
/* TODO (sreek) - return (cc->polling_type == NON_LISTENING) */
return (cc->is_non_listening_server_cq == 1);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment