|
|
@ -303,26 +303,25 @@ static void channel_broadcaster_shutdown(grpc_exec_ctx *exec_ctx, |
|
|
|
* request_matcher |
|
|
|
* request_matcher |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
static void request_matcher_init(request_matcher *request_matcher, |
|
|
|
static void request_matcher_init(request_matcher *rm, size_t entries) { |
|
|
|
size_t entries) { |
|
|
|
memset(rm, 0, sizeof(*rm)); |
|
|
|
memset(request_matcher, 0, sizeof(*request_matcher)); |
|
|
|
rm->requests = gpr_stack_lockfree_create(entries); |
|
|
|
request_matcher->requests = gpr_stack_lockfree_create(entries); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void request_matcher_destroy(request_matcher *request_matcher) { |
|
|
|
static void request_matcher_destroy(request_matcher *rm) { |
|
|
|
GPR_ASSERT(gpr_stack_lockfree_pop(request_matcher->requests) == -1); |
|
|
|
GPR_ASSERT(gpr_stack_lockfree_pop(rm->requests) == -1); |
|
|
|
gpr_stack_lockfree_destroy(request_matcher->requests); |
|
|
|
gpr_stack_lockfree_destroy(rm->requests); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void kill_zombie(grpc_exec_ctx *exec_ctx, void *elem, int success) { |
|
|
|
static void kill_zombie(grpc_exec_ctx *exec_ctx, void *elem, int success) { |
|
|
|
grpc_call_destroy(grpc_call_from_top_element(elem)); |
|
|
|
grpc_call_destroy(grpc_call_from_top_element(elem)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void request_matcher_zombify_all_pending_calls( |
|
|
|
static void request_matcher_zombify_all_pending_calls(grpc_exec_ctx *exec_ctx, |
|
|
|
grpc_exec_ctx *exec_ctx, request_matcher *request_matcher) { |
|
|
|
request_matcher *rm) { |
|
|
|
while (request_matcher->pending_head) { |
|
|
|
while (rm->pending_head) { |
|
|
|
call_data *calld = request_matcher->pending_head; |
|
|
|
call_data *calld = rm->pending_head; |
|
|
|
request_matcher->pending_head = calld->pending_next; |
|
|
|
rm->pending_head = calld->pending_next; |
|
|
|
gpr_mu_lock(&calld->mu_state); |
|
|
|
gpr_mu_lock(&calld->mu_state); |
|
|
|
calld->state = ZOMBIED; |
|
|
|
calld->state = ZOMBIED; |
|
|
|
gpr_mu_unlock(&calld->mu_state); |
|
|
|
gpr_mu_unlock(&calld->mu_state); |
|
|
@ -413,8 +412,7 @@ static void destroy_channel(grpc_exec_ctx *exec_ctx, channel_data *chand) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void finish_start_new_rpc(grpc_exec_ctx *exec_ctx, grpc_server *server, |
|
|
|
static void finish_start_new_rpc(grpc_exec_ctx *exec_ctx, grpc_server *server, |
|
|
|
grpc_call_element *elem, |
|
|
|
grpc_call_element *elem, request_matcher *rm) { |
|
|
|
request_matcher *request_matcher) { |
|
|
|
|
|
|
|
call_data *calld = elem->call_data; |
|
|
|
call_data *calld = elem->call_data; |
|
|
|
int request_id; |
|
|
|
int request_id; |
|
|
|
|
|
|
|
|
|
|
@ -427,17 +425,17 @@ static void finish_start_new_rpc(grpc_exec_ctx *exec_ctx, grpc_server *server, |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
request_id = gpr_stack_lockfree_pop(request_matcher->requests); |
|
|
|
request_id = gpr_stack_lockfree_pop(rm->requests); |
|
|
|
if (request_id == -1) { |
|
|
|
if (request_id == -1) { |
|
|
|
gpr_mu_lock(&server->mu_call); |
|
|
|
gpr_mu_lock(&server->mu_call); |
|
|
|
gpr_mu_lock(&calld->mu_state); |
|
|
|
gpr_mu_lock(&calld->mu_state); |
|
|
|
calld->state = PENDING; |
|
|
|
calld->state = PENDING; |
|
|
|
gpr_mu_unlock(&calld->mu_state); |
|
|
|
gpr_mu_unlock(&calld->mu_state); |
|
|
|
if (request_matcher->pending_head == NULL) { |
|
|
|
if (rm->pending_head == NULL) { |
|
|
|
request_matcher->pending_tail = request_matcher->pending_head = calld; |
|
|
|
rm->pending_tail = rm->pending_head = calld; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
request_matcher->pending_tail->pending_next = calld; |
|
|
|
rm->pending_tail->pending_next = calld; |
|
|
|
request_matcher->pending_tail = calld; |
|
|
|
rm->pending_tail = calld; |
|
|
|
} |
|
|
|
} |
|
|
|
calld->pending_next = NULL; |
|
|
|
calld->pending_next = NULL; |
|
|
|
gpr_mu_unlock(&server->mu_call); |
|
|
|
gpr_mu_unlock(&server->mu_call); |
|
|
@ -1119,7 +1117,7 @@ static grpc_call_error queue_call_request(grpc_exec_ctx *exec_ctx, |
|
|
|
grpc_server *server, |
|
|
|
grpc_server *server, |
|
|
|
requested_call *rc) { |
|
|
|
requested_call *rc) { |
|
|
|
call_data *calld = NULL; |
|
|
|
call_data *calld = NULL; |
|
|
|
request_matcher *request_matcher = NULL; |
|
|
|
request_matcher *rm = NULL; |
|
|
|
int request_id; |
|
|
|
int request_id; |
|
|
|
if (gpr_atm_acq_load(&server->shutdown_flag)) { |
|
|
|
if (gpr_atm_acq_load(&server->shutdown_flag)) { |
|
|
|
fail_call(exec_ctx, server, rc); |
|
|
|
fail_call(exec_ctx, server, rc); |
|
|
@ -1133,22 +1131,22 @@ static grpc_call_error queue_call_request(grpc_exec_ctx *exec_ctx, |
|
|
|
} |
|
|
|
} |
|
|
|
switch (rc->type) { |
|
|
|
switch (rc->type) { |
|
|
|
case BATCH_CALL: |
|
|
|
case BATCH_CALL: |
|
|
|
request_matcher = &server->unregistered_request_matcher; |
|
|
|
rm = &server->unregistered_request_matcher; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case REGISTERED_CALL: |
|
|
|
case REGISTERED_CALL: |
|
|
|
request_matcher = &rc->data.registered.registered_method->request_matcher; |
|
|
|
rm = &rc->data.registered.registered_method->request_matcher; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
server->requested_calls[request_id] = *rc; |
|
|
|
server->requested_calls[request_id] = *rc; |
|
|
|
gpr_free(rc); |
|
|
|
gpr_free(rc); |
|
|
|
if (gpr_stack_lockfree_push(request_matcher->requests, request_id)) { |
|
|
|
if (gpr_stack_lockfree_push(rm->requests, request_id)) { |
|
|
|
/* this was the first queued request: we need to lock and start
|
|
|
|
/* this was the first queued request: we need to lock and start
|
|
|
|
matching calls */ |
|
|
|
matching calls */ |
|
|
|
gpr_mu_lock(&server->mu_call); |
|
|
|
gpr_mu_lock(&server->mu_call); |
|
|
|
while ((calld = request_matcher->pending_head) != NULL) { |
|
|
|
while ((calld = rm->pending_head) != NULL) { |
|
|
|
request_id = gpr_stack_lockfree_pop(request_matcher->requests); |
|
|
|
request_id = gpr_stack_lockfree_pop(rm->requests); |
|
|
|
if (request_id == -1) break; |
|
|
|
if (request_id == -1) break; |
|
|
|
request_matcher->pending_head = calld->pending_next; |
|
|
|
rm->pending_head = calld->pending_next; |
|
|
|
gpr_mu_unlock(&server->mu_call); |
|
|
|
gpr_mu_unlock(&server->mu_call); |
|
|
|
gpr_mu_lock(&calld->mu_state); |
|
|
|
gpr_mu_lock(&calld->mu_state); |
|
|
|
if (calld->state == ZOMBIED) { |
|
|
|
if (calld->state == ZOMBIED) { |
|
|
@ -1204,14 +1202,14 @@ done: |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
grpc_call_error grpc_server_request_registered_call( |
|
|
|
grpc_call_error grpc_server_request_registered_call( |
|
|
|
grpc_server *server, void *rm, grpc_call **call, gpr_timespec *deadline, |
|
|
|
grpc_server *server, void *rmp, grpc_call **call, gpr_timespec *deadline, |
|
|
|
grpc_metadata_array *initial_metadata, grpc_byte_buffer **optional_payload, |
|
|
|
grpc_metadata_array *initial_metadata, grpc_byte_buffer **optional_payload, |
|
|
|
grpc_completion_queue *cq_bound_to_call, |
|
|
|
grpc_completion_queue *cq_bound_to_call, |
|
|
|
grpc_completion_queue *cq_for_notification, void *tag) { |
|
|
|
grpc_completion_queue *cq_for_notification, void *tag) { |
|
|
|
grpc_call_error error; |
|
|
|
grpc_call_error error; |
|
|
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
|
|
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
|
|
|
requested_call *rc = gpr_malloc(sizeof(*rc)); |
|
|
|
requested_call *rc = gpr_malloc(sizeof(*rc)); |
|
|
|
registered_method *registered_method = rm; |
|
|
|
registered_method *rm = rmp; |
|
|
|
if (!grpc_cq_is_server_cq(cq_for_notification)) { |
|
|
|
if (!grpc_cq_is_server_cq(cq_for_notification)) { |
|
|
|
gpr_free(rc); |
|
|
|
gpr_free(rc); |
|
|
|
error = GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE; |
|
|
|
error = GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE; |
|
|
@ -1224,7 +1222,7 @@ grpc_call_error grpc_server_request_registered_call( |
|
|
|
rc->cq_bound_to_call = cq_bound_to_call; |
|
|
|
rc->cq_bound_to_call = cq_bound_to_call; |
|
|
|
rc->cq_for_notification = cq_for_notification; |
|
|
|
rc->cq_for_notification = cq_for_notification; |
|
|
|
rc->call = call; |
|
|
|
rc->call = call; |
|
|
|
rc->data.registered.registered_method = registered_method; |
|
|
|
rc->data.registered.registered_method = rm; |
|
|
|
rc->data.registered.deadline = deadline; |
|
|
|
rc->data.registered.deadline = deadline; |
|
|
|
rc->data.registered.initial_metadata = initial_metadata; |
|
|
|
rc->data.registered.initial_metadata = initial_metadata; |
|
|
|
rc->data.registered.optional_payload = optional_payload; |
|
|
|
rc->data.registered.optional_payload = optional_payload; |
|
|
|