|
|
@ -36,19 +36,18 @@ |
|
|
|
#include <stdio.h> |
|
|
|
#include <stdio.h> |
|
|
|
#include <string.h> |
|
|
|
#include <string.h> |
|
|
|
|
|
|
|
|
|
|
|
#include <grpc/support/alloc.h> |
|
|
|
|
|
|
|
#include <grpc/support/atm.h> |
|
|
|
|
|
|
|
#include <grpc/support/log.h> |
|
|
|
|
|
|
|
#include <grpc/support/time.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "src/core/iomgr/pollset.h" |
|
|
|
|
|
|
|
#include "src/core/iomgr/timer.h" |
|
|
|
#include "src/core/iomgr/timer.h" |
|
|
|
#include "src/core/profiling/timers.h" |
|
|
|
#include "src/core/iomgr/pollset.h" |
|
|
|
#include "src/core/support/string.h" |
|
|
|
#include "src/core/support/string.h" |
|
|
|
#include "src/core/surface/api_trace.h" |
|
|
|
#include "src/core/surface/api_trace.h" |
|
|
|
#include "src/core/surface/call.h" |
|
|
|
#include "src/core/surface/call.h" |
|
|
|
#include "src/core/surface/event_string.h" |
|
|
|
#include "src/core/surface/event_string.h" |
|
|
|
#include "src/core/surface/surface_trace.h" |
|
|
|
#include "src/core/surface/surface_trace.h" |
|
|
|
|
|
|
|
#include "src/core/profiling/timers.h" |
|
|
|
|
|
|
|
#include <grpc/support/alloc.h> |
|
|
|
|
|
|
|
#include <grpc/support/atm.h> |
|
|
|
|
|
|
|
#include <grpc/support/log.h> |
|
|
|
|
|
|
|
#include <grpc/support/time.h> |
|
|
|
|
|
|
|
|
|
|
|
typedef struct { |
|
|
|
typedef struct { |
|
|
|
grpc_pollset_worker **worker; |
|
|
|
grpc_pollset_worker **worker; |
|
|
@ -57,8 +56,6 @@ typedef struct { |
|
|
|
|
|
|
|
|
|
|
|
/* Completion queue structure */ |
|
|
|
/* Completion queue structure */ |
|
|
|
struct grpc_completion_queue { |
|
|
|
struct grpc_completion_queue { |
|
|
|
/** owned by pollset */ |
|
|
|
|
|
|
|
gpr_mu *mu; |
|
|
|
|
|
|
|
/** completed events */ |
|
|
|
/** completed events */ |
|
|
|
grpc_cq_completion completed_head; |
|
|
|
grpc_cq_completion completed_head; |
|
|
|
grpc_cq_completion *completed_tail; |
|
|
|
grpc_cq_completion *completed_tail; |
|
|
@ -66,6 +63,8 @@ struct grpc_completion_queue { |
|
|
|
gpr_refcount pending_events; |
|
|
|
gpr_refcount pending_events; |
|
|
|
/** Once owning_refs drops to zero, we will destroy the cq */ |
|
|
|
/** Once owning_refs drops to zero, we will destroy the cq */ |
|
|
|
gpr_refcount owning_refs; |
|
|
|
gpr_refcount owning_refs; |
|
|
|
|
|
|
|
/** the set of low level i/o things that concern this cq */ |
|
|
|
|
|
|
|
grpc_pollset pollset; |
|
|
|
/** 0 initially, 1 once we've begun shutting down */ |
|
|
|
/** 0 initially, 1 once we've begun shutting down */ |
|
|
|
int shutdown; |
|
|
|
int shutdown; |
|
|
|
int shutdown_called; |
|
|
|
int shutdown_called; |
|
|
@ -83,8 +82,6 @@ struct grpc_completion_queue { |
|
|
|
grpc_completion_queue *next_free; |
|
|
|
grpc_completion_queue *next_free; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
#define POLLSET_FROM_CQ(cq) ((grpc_pollset *)(cq + 1)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static gpr_mu g_freelist_mu; |
|
|
|
static gpr_mu g_freelist_mu; |
|
|
|
grpc_completion_queue *g_freelist; |
|
|
|
grpc_completion_queue *g_freelist; |
|
|
|
|
|
|
|
|
|
|
@ -97,7 +94,7 @@ void grpc_cq_global_shutdown(void) { |
|
|
|
gpr_mu_destroy(&g_freelist_mu); |
|
|
|
gpr_mu_destroy(&g_freelist_mu); |
|
|
|
while (g_freelist) { |
|
|
|
while (g_freelist) { |
|
|
|
grpc_completion_queue *next = g_freelist->next_free; |
|
|
|
grpc_completion_queue *next = g_freelist->next_free; |
|
|
|
grpc_pollset_destroy(POLLSET_FROM_CQ(g_freelist)); |
|
|
|
grpc_pollset_destroy(&g_freelist->pollset); |
|
|
|
#ifndef NDEBUG |
|
|
|
#ifndef NDEBUG |
|
|
|
gpr_free(g_freelist->outstanding_tags); |
|
|
|
gpr_free(g_freelist->outstanding_tags); |
|
|
|
#endif |
|
|
|
#endif |
|
|
@ -127,8 +124,8 @@ grpc_completion_queue *grpc_completion_queue_create(void *reserved) { |
|
|
|
if (g_freelist == NULL) { |
|
|
|
if (g_freelist == NULL) { |
|
|
|
gpr_mu_unlock(&g_freelist_mu); |
|
|
|
gpr_mu_unlock(&g_freelist_mu); |
|
|
|
|
|
|
|
|
|
|
|
cc = gpr_malloc(sizeof(grpc_completion_queue) + grpc_pollset_size()); |
|
|
|
cc = gpr_malloc(sizeof(grpc_completion_queue)); |
|
|
|
grpc_pollset_init(POLLSET_FROM_CQ(cc), &cc->mu); |
|
|
|
grpc_pollset_init(&cc->pollset); |
|
|
|
#ifndef NDEBUG |
|
|
|
#ifndef NDEBUG |
|
|
|
cc->outstanding_tags = NULL; |
|
|
|
cc->outstanding_tags = NULL; |
|
|
|
cc->outstanding_tag_capacity = 0; |
|
|
|
cc->outstanding_tag_capacity = 0; |
|
|
@ -187,7 +184,7 @@ void grpc_cq_internal_unref(grpc_completion_queue *cc) { |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
if (gpr_unref(&cc->owning_refs)) { |
|
|
|
if (gpr_unref(&cc->owning_refs)) { |
|
|
|
GPR_ASSERT(cc->completed_head.next == (uintptr_t)&cc->completed_head); |
|
|
|
GPR_ASSERT(cc->completed_head.next == (uintptr_t)&cc->completed_head); |
|
|
|
grpc_pollset_reset(POLLSET_FROM_CQ(cc)); |
|
|
|
grpc_pollset_reset(&cc->pollset); |
|
|
|
gpr_mu_lock(&g_freelist_mu); |
|
|
|
gpr_mu_lock(&g_freelist_mu); |
|
|
|
cc->next_free = g_freelist; |
|
|
|
cc->next_free = g_freelist; |
|
|
|
g_freelist = cc; |
|
|
|
g_freelist = cc; |
|
|
@ -197,7 +194,7 @@ void grpc_cq_internal_unref(grpc_completion_queue *cc) { |
|
|
|
|
|
|
|
|
|
|
|
void grpc_cq_begin_op(grpc_completion_queue *cc, void *tag) { |
|
|
|
void grpc_cq_begin_op(grpc_completion_queue *cc, void *tag) { |
|
|
|
#ifndef NDEBUG |
|
|
|
#ifndef NDEBUG |
|
|
|
gpr_mu_lock(cc->mu); |
|
|
|
gpr_mu_lock(GRPC_POLLSET_MU(&cc->pollset)); |
|
|
|
GPR_ASSERT(!cc->shutdown_called); |
|
|
|
GPR_ASSERT(!cc->shutdown_called); |
|
|
|
if (cc->outstanding_tag_count == cc->outstanding_tag_capacity) { |
|
|
|
if (cc->outstanding_tag_count == cc->outstanding_tag_capacity) { |
|
|
|
cc->outstanding_tag_capacity = GPR_MAX(4, 2 * cc->outstanding_tag_capacity); |
|
|
|
cc->outstanding_tag_capacity = GPR_MAX(4, 2 * cc->outstanding_tag_capacity); |
|
|
@ -206,7 +203,7 @@ void grpc_cq_begin_op(grpc_completion_queue *cc, void *tag) { |
|
|
|
cc->outstanding_tag_capacity); |
|
|
|
cc->outstanding_tag_capacity); |
|
|
|
} |
|
|
|
} |
|
|
|
cc->outstanding_tags[cc->outstanding_tag_count++] = tag; |
|
|
|
cc->outstanding_tags[cc->outstanding_tag_count++] = tag; |
|
|
|
gpr_mu_unlock(cc->mu); |
|
|
|
gpr_mu_unlock(GRPC_POLLSET_MU(&cc->pollset)); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
gpr_ref(&cc->pending_events); |
|
|
|
gpr_ref(&cc->pending_events); |
|
|
|
} |
|
|
|
} |
|
|
@ -234,7 +231,7 @@ void grpc_cq_end_op(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc, |
|
|
|
storage->next = |
|
|
|
storage->next = |
|
|
|
((uintptr_t)&cc->completed_head) | ((uintptr_t)(success != 0)); |
|
|
|
((uintptr_t)&cc->completed_head) | ((uintptr_t)(success != 0)); |
|
|
|
|
|
|
|
|
|
|
|
gpr_mu_lock(cc->mu); |
|
|
|
gpr_mu_lock(GRPC_POLLSET_MU(&cc->pollset)); |
|
|
|
#ifndef NDEBUG |
|
|
|
#ifndef NDEBUG |
|
|
|
for (i = 0; i < (int)cc->outstanding_tag_count; i++) { |
|
|
|
for (i = 0; i < (int)cc->outstanding_tag_count; i++) { |
|
|
|
if (cc->outstanding_tags[i] == tag) { |
|
|
|
if (cc->outstanding_tags[i] == tag) { |
|
|
@ -259,8 +256,8 @@ void grpc_cq_end_op(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc, |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
grpc_pollset_kick(POLLSET_FROM_CQ(cc), pluck_worker); |
|
|
|
grpc_pollset_kick(&cc->pollset, pluck_worker); |
|
|
|
gpr_mu_unlock(cc->mu); |
|
|
|
gpr_mu_unlock(GRPC_POLLSET_MU(&cc->pollset)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
cc->completed_tail->next = |
|
|
|
cc->completed_tail->next = |
|
|
|
((uintptr_t)storage) | (1u & (uintptr_t)cc->completed_tail->next); |
|
|
|
((uintptr_t)storage) | (1u & (uintptr_t)cc->completed_tail->next); |
|
|
@ -268,9 +265,8 @@ void grpc_cq_end_op(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc, |
|
|
|
GPR_ASSERT(!cc->shutdown); |
|
|
|
GPR_ASSERT(!cc->shutdown); |
|
|
|
GPR_ASSERT(cc->shutdown_called); |
|
|
|
GPR_ASSERT(cc->shutdown_called); |
|
|
|
cc->shutdown = 1; |
|
|
|
cc->shutdown = 1; |
|
|
|
grpc_pollset_shutdown(exec_ctx, POLLSET_FROM_CQ(cc), |
|
|
|
grpc_pollset_shutdown(exec_ctx, &cc->pollset, &cc->pollset_shutdown_done); |
|
|
|
&cc->pollset_shutdown_done); |
|
|
|
gpr_mu_unlock(GRPC_POLLSET_MU(&cc->pollset)); |
|
|
|
gpr_mu_unlock(cc->mu); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
GPR_TIMER_END("grpc_cq_end_op", 0); |
|
|
|
GPR_TIMER_END("grpc_cq_end_op", 0); |
|
|
@ -298,7 +294,7 @@ grpc_event grpc_completion_queue_next(grpc_completion_queue *cc, |
|
|
|
deadline = gpr_convert_clock_type(deadline, GPR_CLOCK_MONOTONIC); |
|
|
|
deadline = gpr_convert_clock_type(deadline, GPR_CLOCK_MONOTONIC); |
|
|
|
|
|
|
|
|
|
|
|
GRPC_CQ_INTERNAL_REF(cc, "next"); |
|
|
|
GRPC_CQ_INTERNAL_REF(cc, "next"); |
|
|
|
gpr_mu_lock(cc->mu); |
|
|
|
gpr_mu_lock(GRPC_POLLSET_MU(&cc->pollset)); |
|
|
|
for (;;) { |
|
|
|
for (;;) { |
|
|
|
if (cc->completed_tail != &cc->completed_head) { |
|
|
|
if (cc->completed_tail != &cc->completed_head) { |
|
|
|
grpc_cq_completion *c = (grpc_cq_completion *)cc->completed_head.next; |
|
|
|
grpc_cq_completion *c = (grpc_cq_completion *)cc->completed_head.next; |
|
|
@ -306,7 +302,7 @@ grpc_event grpc_completion_queue_next(grpc_completion_queue *cc, |
|
|
|
if (c == cc->completed_tail) { |
|
|
|
if (c == cc->completed_tail) { |
|
|
|
cc->completed_tail = &cc->completed_head; |
|
|
|
cc->completed_tail = &cc->completed_head; |
|
|
|
} |
|
|
|
} |
|
|
|
gpr_mu_unlock(cc->mu); |
|
|
|
gpr_mu_unlock(GRPC_POLLSET_MU(&cc->pollset)); |
|
|
|
ret.type = GRPC_OP_COMPLETE; |
|
|
|
ret.type = GRPC_OP_COMPLETE; |
|
|
|
ret.success = c->next & 1u; |
|
|
|
ret.success = c->next & 1u; |
|
|
|
ret.tag = c->tag; |
|
|
|
ret.tag = c->tag; |
|
|
@ -314,14 +310,14 @@ grpc_event grpc_completion_queue_next(grpc_completion_queue *cc, |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if (cc->shutdown) { |
|
|
|
if (cc->shutdown) { |
|
|
|
gpr_mu_unlock(cc->mu); |
|
|
|
gpr_mu_unlock(GRPC_POLLSET_MU(&cc->pollset)); |
|
|
|
memset(&ret, 0, sizeof(ret)); |
|
|
|
memset(&ret, 0, sizeof(ret)); |
|
|
|
ret.type = GRPC_QUEUE_SHUTDOWN; |
|
|
|
ret.type = GRPC_QUEUE_SHUTDOWN; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
now = gpr_now(GPR_CLOCK_MONOTONIC); |
|
|
|
now = gpr_now(GPR_CLOCK_MONOTONIC); |
|
|
|
if (!first_loop && gpr_time_cmp(now, deadline) >= 0) { |
|
|
|
if (!first_loop && gpr_time_cmp(now, deadline) >= 0) { |
|
|
|
gpr_mu_unlock(cc->mu); |
|
|
|
gpr_mu_unlock(GRPC_POLLSET_MU(&cc->pollset)); |
|
|
|
memset(&ret, 0, sizeof(ret)); |
|
|
|
memset(&ret, 0, sizeof(ret)); |
|
|
|
ret.type = GRPC_QUEUE_TIMEOUT; |
|
|
|
ret.type = GRPC_QUEUE_TIMEOUT; |
|
|
|
break; |
|
|
|
break; |
|
|
@ -334,12 +330,11 @@ grpc_event grpc_completion_queue_next(grpc_completion_queue *cc, |
|
|
|
gpr_timespec iteration_deadline = deadline; |
|
|
|
gpr_timespec iteration_deadline = deadline; |
|
|
|
if (grpc_timer_check(&exec_ctx, now, &iteration_deadline)) { |
|
|
|
if (grpc_timer_check(&exec_ctx, now, &iteration_deadline)) { |
|
|
|
GPR_TIMER_MARK("alarm_triggered", 0); |
|
|
|
GPR_TIMER_MARK("alarm_triggered", 0); |
|
|
|
gpr_mu_unlock(cc->mu); |
|
|
|
gpr_mu_unlock(GRPC_POLLSET_MU(&cc->pollset)); |
|
|
|
grpc_exec_ctx_flush(&exec_ctx); |
|
|
|
grpc_exec_ctx_flush(&exec_ctx); |
|
|
|
gpr_mu_lock(cc->mu); |
|
|
|
gpr_mu_lock(GRPC_POLLSET_MU(&cc->pollset)); |
|
|
|
continue; |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
grpc_pollset_work(&exec_ctx, POLLSET_FROM_CQ(cc), &worker, now, |
|
|
|
grpc_pollset_work(&exec_ctx, &cc->pollset, &worker, now, |
|
|
|
iteration_deadline); |
|
|
|
iteration_deadline); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -400,7 +395,7 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cc, void *tag, |
|
|
|
deadline = gpr_convert_clock_type(deadline, GPR_CLOCK_MONOTONIC); |
|
|
|
deadline = gpr_convert_clock_type(deadline, GPR_CLOCK_MONOTONIC); |
|
|
|
|
|
|
|
|
|
|
|
GRPC_CQ_INTERNAL_REF(cc, "pluck"); |
|
|
|
GRPC_CQ_INTERNAL_REF(cc, "pluck"); |
|
|
|
gpr_mu_lock(cc->mu); |
|
|
|
gpr_mu_lock(GRPC_POLLSET_MU(&cc->pollset)); |
|
|
|
for (;;) { |
|
|
|
for (;;) { |
|
|
|
prev = &cc->completed_head; |
|
|
|
prev = &cc->completed_head; |
|
|
|
while ((c = (grpc_cq_completion *)(prev->next & ~(uintptr_t)1)) != |
|
|
|
while ((c = (grpc_cq_completion *)(prev->next & ~(uintptr_t)1)) != |
|
|
@ -410,7 +405,7 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cc, void *tag, |
|
|
|
if (c == cc->completed_tail) { |
|
|
|
if (c == cc->completed_tail) { |
|
|
|
cc->completed_tail = prev; |
|
|
|
cc->completed_tail = prev; |
|
|
|
} |
|
|
|
} |
|
|
|
gpr_mu_unlock(cc->mu); |
|
|
|
gpr_mu_unlock(GRPC_POLLSET_MU(&cc->pollset)); |
|
|
|
ret.type = GRPC_OP_COMPLETE; |
|
|
|
ret.type = GRPC_OP_COMPLETE; |
|
|
|
ret.success = c->next & 1u; |
|
|
|
ret.success = c->next & 1u; |
|
|
|
ret.tag = c->tag; |
|
|
|
ret.tag = c->tag; |
|
|
@ -420,7 +415,7 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cc, void *tag, |
|
|
|
prev = c; |
|
|
|
prev = c; |
|
|
|
} |
|
|
|
} |
|
|
|
if (cc->shutdown) { |
|
|
|
if (cc->shutdown) { |
|
|
|
gpr_mu_unlock(cc->mu); |
|
|
|
gpr_mu_unlock(GRPC_POLLSET_MU(&cc->pollset)); |
|
|
|
memset(&ret, 0, sizeof(ret)); |
|
|
|
memset(&ret, 0, sizeof(ret)); |
|
|
|
ret.type = GRPC_QUEUE_SHUTDOWN; |
|
|
|
ret.type = GRPC_QUEUE_SHUTDOWN; |
|
|
|
break; |
|
|
|
break; |
|
|
@ -430,7 +425,7 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cc, void *tag, |
|
|
|
"Too many outstanding grpc_completion_queue_pluck calls: maximum " |
|
|
|
"Too many outstanding grpc_completion_queue_pluck calls: maximum " |
|
|
|
"is %d", |
|
|
|
"is %d", |
|
|
|
GRPC_MAX_COMPLETION_QUEUE_PLUCKERS); |
|
|
|
GRPC_MAX_COMPLETION_QUEUE_PLUCKERS); |
|
|
|
gpr_mu_unlock(cc->mu); |
|
|
|
gpr_mu_unlock(GRPC_POLLSET_MU(&cc->pollset)); |
|
|
|
memset(&ret, 0, sizeof(ret)); |
|
|
|
memset(&ret, 0, sizeof(ret)); |
|
|
|
/* TODO(ctiller): should we use a different result here */ |
|
|
|
/* TODO(ctiller): should we use a different result here */ |
|
|
|
ret.type = GRPC_QUEUE_TIMEOUT; |
|
|
|
ret.type = GRPC_QUEUE_TIMEOUT; |
|
|
@ -439,7 +434,7 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cc, void *tag, |
|
|
|
now = gpr_now(GPR_CLOCK_MONOTONIC); |
|
|
|
now = gpr_now(GPR_CLOCK_MONOTONIC); |
|
|
|
if (!first_loop && gpr_time_cmp(now, deadline) >= 0) { |
|
|
|
if (!first_loop && gpr_time_cmp(now, deadline) >= 0) { |
|
|
|
del_plucker(cc, tag, &worker); |
|
|
|
del_plucker(cc, tag, &worker); |
|
|
|
gpr_mu_unlock(cc->mu); |
|
|
|
gpr_mu_unlock(GRPC_POLLSET_MU(&cc->pollset)); |
|
|
|
memset(&ret, 0, sizeof(ret)); |
|
|
|
memset(&ret, 0, sizeof(ret)); |
|
|
|
ret.type = GRPC_QUEUE_TIMEOUT; |
|
|
|
ret.type = GRPC_QUEUE_TIMEOUT; |
|
|
|
break; |
|
|
|
break; |
|
|
@ -452,12 +447,11 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cc, void *tag, |
|
|
|
gpr_timespec iteration_deadline = deadline; |
|
|
|
gpr_timespec iteration_deadline = deadline; |
|
|
|
if (grpc_timer_check(&exec_ctx, now, &iteration_deadline)) { |
|
|
|
if (grpc_timer_check(&exec_ctx, now, &iteration_deadline)) { |
|
|
|
GPR_TIMER_MARK("alarm_triggered", 0); |
|
|
|
GPR_TIMER_MARK("alarm_triggered", 0); |
|
|
|
gpr_mu_unlock(cc->mu); |
|
|
|
gpr_mu_unlock(GRPC_POLLSET_MU(&cc->pollset)); |
|
|
|
grpc_exec_ctx_flush(&exec_ctx); |
|
|
|
grpc_exec_ctx_flush(&exec_ctx); |
|
|
|
gpr_mu_lock(cc->mu); |
|
|
|
gpr_mu_lock(GRPC_POLLSET_MU(&cc->pollset)); |
|
|
|
continue; |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
grpc_pollset_work(&exec_ctx, POLLSET_FROM_CQ(cc), &worker, now, |
|
|
|
grpc_pollset_work(&exec_ctx, &cc->pollset, &worker, now, |
|
|
|
iteration_deadline); |
|
|
|
iteration_deadline); |
|
|
|
} |
|
|
|
} |
|
|
|
del_plucker(cc, tag, &worker); |
|
|
|
del_plucker(cc, tag, &worker); |
|
|
@ -478,9 +472,9 @@ void grpc_completion_queue_shutdown(grpc_completion_queue *cc) { |
|
|
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
|
|
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
|
|
|
GPR_TIMER_BEGIN("grpc_completion_queue_shutdown", 0); |
|
|
|
GPR_TIMER_BEGIN("grpc_completion_queue_shutdown", 0); |
|
|
|
GRPC_API_TRACE("grpc_completion_queue_shutdown(cc=%p)", 1, (cc)); |
|
|
|
GRPC_API_TRACE("grpc_completion_queue_shutdown(cc=%p)", 1, (cc)); |
|
|
|
gpr_mu_lock(cc->mu); |
|
|
|
gpr_mu_lock(GRPC_POLLSET_MU(&cc->pollset)); |
|
|
|
if (cc->shutdown_called) { |
|
|
|
if (cc->shutdown_called) { |
|
|
|
gpr_mu_unlock(cc->mu); |
|
|
|
gpr_mu_unlock(GRPC_POLLSET_MU(&cc->pollset)); |
|
|
|
GPR_TIMER_END("grpc_completion_queue_shutdown", 0); |
|
|
|
GPR_TIMER_END("grpc_completion_queue_shutdown", 0); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -488,10 +482,9 @@ void grpc_completion_queue_shutdown(grpc_completion_queue *cc) { |
|
|
|
if (gpr_unref(&cc->pending_events)) { |
|
|
|
if (gpr_unref(&cc->pending_events)) { |
|
|
|
GPR_ASSERT(!cc->shutdown); |
|
|
|
GPR_ASSERT(!cc->shutdown); |
|
|
|
cc->shutdown = 1; |
|
|
|
cc->shutdown = 1; |
|
|
|
grpc_pollset_shutdown(&exec_ctx, POLLSET_FROM_CQ(cc), |
|
|
|
grpc_pollset_shutdown(&exec_ctx, &cc->pollset, &cc->pollset_shutdown_done); |
|
|
|
&cc->pollset_shutdown_done); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
gpr_mu_unlock(cc->mu); |
|
|
|
gpr_mu_unlock(GRPC_POLLSET_MU(&cc->pollset)); |
|
|
|
grpc_exec_ctx_finish(&exec_ctx); |
|
|
|
grpc_exec_ctx_finish(&exec_ctx); |
|
|
|
GPR_TIMER_END("grpc_completion_queue_shutdown", 0); |
|
|
|
GPR_TIMER_END("grpc_completion_queue_shutdown", 0); |
|
|
|
} |
|
|
|
} |
|
|
@ -505,7 +498,7 @@ void grpc_completion_queue_destroy(grpc_completion_queue *cc) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
grpc_pollset *grpc_cq_pollset(grpc_completion_queue *cc) { |
|
|
|
grpc_pollset *grpc_cq_pollset(grpc_completion_queue *cc) { |
|
|
|
return POLLSET_FROM_CQ(cc); |
|
|
|
return &cc->pollset; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void grpc_cq_mark_server_cq(grpc_completion_queue *cc) { cc->is_server_cq = 1; } |
|
|
|
void grpc_cq_mark_server_cq(grpc_completion_queue *cc) { cc->is_server_cq = 1; } |
|
|
|