|
|
@ -298,15 +298,15 @@ static void channel_broadcaster_shutdown(channel_broadcaster *cb, |
|
|
|
* 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(request_matcher, 0, sizeof(*request_matcher)); |
|
|
|
memset(rm, 0, sizeof(*rm)); |
|
|
|
request_matcher->requests = gpr_stack_lockfree_create(entries); |
|
|
|
rm->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(void *elem, int success) { |
|
|
|
static void kill_zombie(void *elem, int success) { |
|
|
@ -314,10 +314,10 @@ static void kill_zombie(void *elem, int success) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void request_matcher_zombify_all_pending_calls( |
|
|
|
static void request_matcher_zombify_all_pending_calls( |
|
|
|
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); |
|
|
@ -405,7 +405,7 @@ static void destroy_channel(channel_data *chand) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void finish_start_new_rpc(grpc_server *server, grpc_call_element *elem, |
|
|
|
static void finish_start_new_rpc(grpc_server *server, grpc_call_element *elem, |
|
|
|
request_matcher *request_matcher) { |
|
|
|
request_matcher *rm) { |
|
|
|
call_data *calld = elem->call_data; |
|
|
|
call_data *calld = elem->call_data; |
|
|
|
int request_id; |
|
|
|
int request_id; |
|
|
|
|
|
|
|
|
|
|
@ -418,17 +418,17 @@ static void finish_start_new_rpc(grpc_server *server, grpc_call_element *elem, |
|
|
|
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); |
|
|
@ -1082,7 +1082,7 @@ void grpc_server_add_listener(grpc_server *server, void *arg, |
|
|
|
static grpc_call_error queue_call_request(grpc_server *server, |
|
|
|
static grpc_call_error queue_call_request(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(server, rc); |
|
|
|
fail_call(server, rc); |
|
|
@ -1096,22 +1096,22 @@ static grpc_call_error queue_call_request(grpc_server *server, |
|
|
|
} |
|
|
|
} |
|
|
|
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) { |
|
|
@ -1160,12 +1160,12 @@ grpc_call_error grpc_server_request_call( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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) { |
|
|
|
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); |
|
|
|
return GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE; |
|
|
|
return GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE; |
|
|
@ -1177,7 +1177,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; |
|
|
|