GRPC Core  9.0.0
Data Structures | Macros | Functions | Variables
completion_queue.cc File Reference
#include <grpc/support/port_platform.h>
#include "src/core/lib/surface/completion_queue.h"
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
#include <grpc/support/alloc.h>
#include <grpc/support/atm.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include <grpc/support/time.h>
#include "src/core/lib/debug/stats.h"
#include "src/core/lib/gpr/spinlock.h"
#include "src/core/lib/gpr/tls.h"
#include "src/core/lib/gprpp/atomic.h"
#include "src/core/lib/iomgr/executor.h"
#include "src/core/lib/iomgr/pollset.h"
#include "src/core/lib/iomgr/timer.h"
#include "src/core/lib/profiling/timers.h"
#include "src/core/lib/surface/api_trace.h"
#include "src/core/lib/surface/call.h"
#include "src/core/lib/surface/event_string.h"

Data Structures

struct  cq_vtable
 
struct  grpc_completion_queue
 
struct  cq_is_finished_arg
 
class  ExecCtxNext
 
class  ExecCtxPluck
 

Macros

#define DATA_FROM_CQ(cq)   ((void*)(cq + 1))
 
#define POLLSET_FROM_CQ(cq)    ((grpc_pollset*)(cq->vtable->data_size + (char*)DATA_FROM_CQ(cq)))
 
#define GRPC_SURFACE_TRACE_RETURNED_EVENT(cq, event)
 

Functions

void grpc_cq_global_init ()
 
void grpc_completion_queue_thread_local_cache_init (grpc_completion_queue *cq)
 Initializes a thread local cache for cq. More...
 
int grpc_completion_queue_thread_local_cache_flush (grpc_completion_queue *cq, void **tag, int *ok)
 Flushes the thread local cache for cq. More...
 
grpc_completion_queuegrpc_completion_queue_create_internal (grpc_cq_completion_type completion_type, grpc_cq_polling_type polling_type, grpc_experimental_completion_queue_functor *shutdown_callback)
 
grpc_cq_completion_type grpc_get_cq_completion_type (grpc_completion_queue *cq)
 
int grpc_get_cq_poll_num (grpc_completion_queue *cq)
 
void grpc_cq_internal_ref (grpc_completion_queue *cq, const char *reason, const char *file, int line)
 
void grpc_cq_internal_unref (grpc_completion_queue *cq, const char *reason, const char *file, int line)
 
bool grpc_cq_begin_op (grpc_completion_queue *cq, void *tag)
 
void grpc_cq_end_op (grpc_completion_queue *cq, void *tag, grpc_error *error, void(*done)(void *done_arg, grpc_cq_completion *storage), void *done_arg, grpc_cq_completion *storage, bool internal)
 
grpc_event grpc_completion_queue_next (grpc_completion_queue *cq, gpr_timespec deadline, void *reserved)
 Blocks until an event is available, the completion queue is being shut down, or deadline is reached. More...
 
grpc_event grpc_completion_queue_pluck (grpc_completion_queue *cq, void *tag, gpr_timespec deadline, void *reserved)
 Blocks until an event with tag 'tag' is available, the completion queue is being shutdown or deadline is reached. More...
 
void grpc_completion_queue_shutdown (grpc_completion_queue *cq)
 Begin destruction of a completion queue. More...
 
void grpc_completion_queue_destroy (grpc_completion_queue *cq)
 Destroy a completion queue. More...
 
grpc_pollsetgrpc_cq_pollset (grpc_completion_queue *cq)
 
bool grpc_cq_can_listen (grpc_completion_queue *cq)
 

Variables

grpc_core::TraceFlag grpc_trace_operation_failures (false, "op_failure")
 
grpc_core::DebugOnlyTraceFlag grpc_trace_pending_tags (false, "pending_tags")
 
grpc_core::DebugOnlyTraceFlag grpc_trace_cq_refcount (false, "cq_refcount")
 
grpc_core::TraceFlag grpc_cq_pluck_trace (false, "queue_pluck")
 

Macro Definition Documentation

◆ DATA_FROM_CQ

#define DATA_FROM_CQ (   cq)    ((void*)(cq + 1))

◆ GRPC_SURFACE_TRACE_RETURNED_EVENT

#define GRPC_SURFACE_TRACE_RETURNED_EVENT (   cq,
  event 
)
Value:
do { \
(event)->type != GRPC_QUEUE_TIMEOUT)) { \
char* _ev = grpc_event_string(event); \
gpr_log(GPR_INFO, "RETURN_EVENT[%p]: %s", cq, _ev); \
gpr_free(_ev); \
} \
} while (0)
grpc_core::TraceFlag grpc_api_trace(false, "api")
grpc_core::TraceFlag grpc_cq_pluck_trace(false, "queue_pluck")
char * grpc_event_string(grpc_event *ev)
Definition: event_string.cc:43
@ GRPC_QUEUE_TIMEOUT
No event before timeout.
Definition: grpc_types.h:506
#define GPR_INFO
Definition: log.h:56
#define GRPC_TRACE_FLAG_ENABLED(f)
Definition: trace.h:112

◆ POLLSET_FROM_CQ

#define POLLSET_FROM_CQ (   cq)     ((grpc_pollset*)(cq->vtable->data_size + (char*)DATA_FROM_CQ(cq)))

Function Documentation

◆ grpc_completion_queue_create_internal()

grpc_completion_queue* grpc_completion_queue_create_internal ( grpc_cq_completion_type  completion_type,
grpc_cq_polling_type  polling_type,
grpc_experimental_completion_queue_functor shutdown_callback 
)

◆ grpc_completion_queue_destroy()

void grpc_completion_queue_destroy ( grpc_completion_queue cq)

Destroy a completion queue.

The caller must ensure that the queue is drained and no threads are executing grpc_completion_queue_next

◆ grpc_completion_queue_next()

grpc_event grpc_completion_queue_next ( grpc_completion_queue cq,
gpr_timespec  deadline,
void *  reserved 
)

Blocks until an event is available, the completion queue is being shut down, or deadline is reached.

Returns a grpc_event with type GRPC_QUEUE_TIMEOUT on timeout, otherwise a grpc_event describing the event that occurred.

Callers must not call grpc_completion_queue_next and grpc_completion_queue_pluck simultaneously on the same completion queue.

◆ grpc_completion_queue_pluck()

grpc_event grpc_completion_queue_pluck ( grpc_completion_queue cq,
void *  tag,
gpr_timespec  deadline,
void *  reserved 
)

Blocks until an event with tag 'tag' is available, the completion queue is being shutdown or deadline is reached.

Returns a grpc_event with type GRPC_QUEUE_TIMEOUT on timeout, otherwise a grpc_event describing the event that occurred.

Callers must not call grpc_completion_queue_next and grpc_completion_queue_pluck simultaneously on the same completion queue.

Completion queues support a maximum of GRPC_MAX_COMPLETION_QUEUE_PLUCKERS concurrently executing plucks at any time.

◆ grpc_completion_queue_shutdown()

void grpc_completion_queue_shutdown ( grpc_completion_queue cq)

Begin destruction of a completion queue.

Once all possible events are drained then grpc_completion_queue_next will start to produce GRPC_QUEUE_SHUTDOWN events only. At that point it's safe to call grpc_completion_queue_destroy.

After calling this function applications should ensure that no NEW work is added to be published on this completion queue.

◆ grpc_completion_queue_thread_local_cache_flush()

int grpc_completion_queue_thread_local_cache_flush ( grpc_completion_queue cq,
void **  tag,
int *  ok 
)

Flushes the thread local cache for cq.

Returns 1 if there was contents in the cache. If there was an event in cq tls cache, its tag is placed in tag, and ok is set to the event success.

◆ grpc_completion_queue_thread_local_cache_init()

void grpc_completion_queue_thread_local_cache_init ( grpc_completion_queue cq)

Initializes a thread local cache for cq.

grpc_flush_cq_tls_cache() MUST be called on the same thread, with the same cq.

◆ grpc_cq_begin_op()

bool grpc_cq_begin_op ( grpc_completion_queue cq,
void *  tag 
)

◆ grpc_cq_can_listen()

bool grpc_cq_can_listen ( grpc_completion_queue cq)

◆ grpc_cq_end_op()

void grpc_cq_end_op ( grpc_completion_queue cq,
void *  tag,
grpc_error error,
void(*)(void *done_arg, grpc_cq_completion *storage)  done,
void *  done_arg,
grpc_cq_completion storage,
bool  internal 
)

◆ grpc_cq_global_init()

void grpc_cq_global_init ( )

◆ grpc_cq_internal_ref()

void grpc_cq_internal_ref ( grpc_completion_queue cq,
const char *  reason,
const char *  file,
int  line 
)

◆ grpc_cq_internal_unref()

void grpc_cq_internal_unref ( grpc_completion_queue cq,
const char *  reason,
const char *  file,
int  line 
)

◆ grpc_cq_pollset()

grpc_pollset* grpc_cq_pollset ( grpc_completion_queue cq)

◆ grpc_get_cq_completion_type()

grpc_cq_completion_type grpc_get_cq_completion_type ( grpc_completion_queue cq)

◆ grpc_get_cq_poll_num()

int grpc_get_cq_poll_num ( grpc_completion_queue cq)

Variable Documentation

◆ grpc_cq_pluck_trace

grpc_core::TraceFlag grpc_cq_pluck_trace(false, "queue_pluck") ( false  ,
"queue_pluck"   
)

◆ grpc_trace_cq_refcount

grpc_core::DebugOnlyTraceFlag grpc_trace_cq_refcount(false, "cq_refcount") ( false  ,
"cq_refcount"   
)

◆ grpc_trace_operation_failures

grpc_core::TraceFlag grpc_trace_operation_failures(false, "op_failure") ( false  ,
"op_failure"   
)

◆ grpc_trace_pending_tags

grpc_core::DebugOnlyTraceFlag grpc_trace_pending_tags(false, "pending_tags") ( false  ,
"pending_tags"   
)