diff options
Diffstat (limited to 'src/core/lib/surface')
-rw-r--r-- | src/core/lib/surface/byte_buffer.c | 8 | ||||
-rw-r--r-- | src/core/lib/surface/byte_buffer_reader.c | 16 | ||||
-rw-r--r-- | src/core/lib/surface/call.c | 100 | ||||
-rw-r--r-- | src/core/lib/surface/call.h | 3 | ||||
-rw-r--r-- | src/core/lib/surface/channel.c | 78 | ||||
-rw-r--r-- | src/core/lib/surface/channel.h | 10 | ||||
-rw-r--r-- | src/core/lib/surface/channel_init.c | 2 | ||||
-rw-r--r-- | src/core/lib/surface/channel_init.h | 3 | ||||
-rw-r--r-- | src/core/lib/surface/init.c | 17 | ||||
-rw-r--r-- | src/core/lib/surface/init_secure.c | 4 | ||||
-rw-r--r-- | src/core/lib/surface/lame_client.c | 11 | ||||
-rw-r--r-- | src/core/lib/surface/server.c | 21 |
12 files changed, 158 insertions, 115 deletions
diff --git a/src/core/lib/surface/byte_buffer.c b/src/core/lib/surface/byte_buffer.c index d646591a65..c8e2fdfdad 100644 --- a/src/core/lib/surface/byte_buffer.c +++ b/src/core/lib/surface/byte_buffer.c @@ -35,6 +35,8 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> +#include "src/core/lib/slice/slice_internal.h" + grpc_byte_buffer *grpc_raw_byte_buffer_create(grpc_slice *slices, size_t nslices) { return grpc_raw_compressed_byte_buffer_create(slices, nslices, @@ -50,7 +52,7 @@ grpc_byte_buffer *grpc_raw_compressed_byte_buffer_create( bb->data.raw.compression = compression; grpc_slice_buffer_init(&bb->data.raw.slice_buffer); for (i = 0; i < nslices; i++) { - grpc_slice_ref(slices[i]); + grpc_slice_ref_internal(slices[i]); grpc_slice_buffer_add(&bb->data.raw.slice_buffer, slices[i]); } return bb; @@ -82,12 +84,14 @@ grpc_byte_buffer *grpc_byte_buffer_copy(grpc_byte_buffer *bb) { void grpc_byte_buffer_destroy(grpc_byte_buffer *bb) { if (!bb) return; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; switch (bb->type) { case GRPC_BB_RAW: - grpc_slice_buffer_destroy(&bb->data.raw.slice_buffer); + grpc_slice_buffer_destroy_internal(&exec_ctx, &bb->data.raw.slice_buffer); break; } gpr_free(bb); + grpc_exec_ctx_finish(&exec_ctx); } size_t grpc_byte_buffer_length(grpc_byte_buffer *bb) { diff --git a/src/core/lib/surface/byte_buffer_reader.c b/src/core/lib/surface/byte_buffer_reader.c index 0089959fbb..1a6ccdaddb 100644 --- a/src/core/lib/surface/byte_buffer_reader.c +++ b/src/core/lib/surface/byte_buffer_reader.c @@ -42,6 +42,7 @@ #include <grpc/support/log.h> #include "src/core/lib/compression/message_compress.h" +#include "src/core/lib/slice/slice_internal.h" static int is_compressed(grpc_byte_buffer *buffer) { switch (buffer->type) { @@ -56,13 +57,15 @@ static int is_compressed(grpc_byte_buffer *buffer) { int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader *reader, grpc_byte_buffer *buffer) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_slice_buffer decompressed_slices_buffer; reader->buffer_in = buffer; switch (reader->buffer_in->type) { case GRPC_BB_RAW: grpc_slice_buffer_init(&decompressed_slices_buffer); if (is_compressed(reader->buffer_in)) { - if (grpc_msg_decompress(reader->buffer_in->data.raw.compression, + if (grpc_msg_decompress(&exec_ctx, + reader->buffer_in->data.raw.compression, &reader->buffer_in->data.raw.slice_buffer, &decompressed_slices_buffer) == 0) { gpr_log(GPR_ERROR, @@ -76,13 +79,15 @@ int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader *reader, grpc_raw_byte_buffer_create(decompressed_slices_buffer.slices, decompressed_slices_buffer.count); } - grpc_slice_buffer_destroy(&decompressed_slices_buffer); + grpc_slice_buffer_destroy_internal(&exec_ctx, + &decompressed_slices_buffer); } else { /* not compressed, use the input buffer as output */ reader->buffer_out = reader->buffer_in; } reader->current.index = 0; break; } + grpc_exec_ctx_finish(&exec_ctx); return 1; } @@ -104,7 +109,8 @@ int grpc_byte_buffer_reader_next(grpc_byte_buffer_reader *reader, grpc_slice_buffer *slice_buffer; slice_buffer = &reader->buffer_out->data.raw.slice_buffer; if (reader->current.index < slice_buffer->count) { - *slice = grpc_slice_ref(slice_buffer->slices[reader->current.index]); + *slice = grpc_slice_ref_internal( + slice_buffer->slices[reader->current.index]); reader->current.index += 1; return 1; } @@ -121,12 +127,14 @@ grpc_slice grpc_byte_buffer_reader_readall(grpc_byte_buffer_reader *reader) { grpc_slice out_slice = grpc_slice_malloc(input_size); uint8_t *const outbuf = GRPC_SLICE_START_PTR(out_slice); /* just an alias */ + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; while (grpc_byte_buffer_reader_next(reader, &in_slice) != 0) { const size_t slice_length = GRPC_SLICE_LENGTH(in_slice); memcpy(&(outbuf[bytes_read]), GRPC_SLICE_START_PTR(in_slice), slice_length); bytes_read += slice_length; - grpc_slice_unref(in_slice); + grpc_slice_unref_internal(&exec_ctx, in_slice); GPR_ASSERT(bytes_read <= input_size); } + grpc_exec_ctx_finish(&exec_ctx); return out_slice; } diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index 8ca3cab9d5..5c985003e5 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -49,6 +49,7 @@ #include "src/core/lib/compression/algorithm_metadata.h" #include "src/core/lib/iomgr/timer.h" #include "src/core/lib/profiling/timers.h" +#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/support/string.h" #include "src/core/lib/surface/api_trace.h" @@ -226,12 +227,12 @@ static void destroy_call(grpc_exec_ctx *exec_ctx, void *call_stack, static void receiving_slice_ready(grpc_exec_ctx *exec_ctx, void *bctlp, grpc_error *error); -grpc_error *grpc_call_create(const grpc_call_create_args *args, +grpc_error *grpc_call_create(grpc_exec_ctx *exec_ctx, + const grpc_call_create_args *args, grpc_call **out_call) { size_t i, j; grpc_channel_stack *channel_stack = grpc_channel_get_channel_stack(args->channel); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_call *call; GPR_TIMER_BEGIN("grpc_call_create", 0); call = gpr_malloc(sizeof(grpc_call) + channel_stack->call_stack_size); @@ -315,14 +316,14 @@ grpc_error *grpc_call_create(const grpc_call_create_args *args, GRPC_CHANNEL_INTERNAL_REF(args->channel, "call"); /* initial refcount dropped by grpc_call_destroy */ grpc_error *error = grpc_call_stack_init( - &exec_ctx, channel_stack, 1, destroy_call, call, call->context, + exec_ctx, channel_stack, 1, destroy_call, call, call->context, args->server_transport_data, path, call->start_time, send_deadline, CALL_STACK_FROM_CALL(call)); if (error != GRPC_ERROR_NONE) { grpc_status_code status; const char *error_str; grpc_error_get_status(error, &status, &error_str); - close_with_status(&exec_ctx, call, status, error_str); + close_with_status(exec_ctx, call, status, error_str); } if (args->cq != NULL) { GPR_ASSERT( @@ -338,12 +339,11 @@ grpc_error *grpc_call_create(const grpc_call_create_args *args, } if (!grpc_polling_entity_is_empty(&call->pollent)) { grpc_call_stack_set_pollset_or_pollset_set( - &exec_ctx, CALL_STACK_FROM_CALL(call), &call->pollent); + exec_ctx, CALL_STACK_FROM_CALL(call), &call->pollent); } - if (path != NULL) GRPC_MDSTR_UNREF(path); + if (path != NULL) GRPC_MDSTR_UNREF(exec_ctx, path); - grpc_exec_ctx_finish(&exec_ctx); GPR_TIMER_END("grpc_call_create", 0); return error; } @@ -404,7 +404,7 @@ static void destroy_call(grpc_exec_ctx *exec_ctx, void *call, GPR_TIMER_BEGIN("destroy_call", 0); for (i = 0; i < 2; i++) { grpc_metadata_batch_destroy( - &c->metadata_batch[1 /* is_receiving */][i /* is_initial */]); + exec_ctx, &c->metadata_batch[1 /* is_receiving */][i /* is_initial */]); } if (c->receiving_stream != NULL) { grpc_byte_stream_destroy(exec_ctx, c->receiving_stream); @@ -412,11 +412,11 @@ static void destroy_call(grpc_exec_ctx *exec_ctx, void *call, gpr_mu_destroy(&c->mu); for (i = 0; i < STATUS_SOURCE_COUNT; i++) { if (c->status[i].details) { - GRPC_MDSTR_UNREF(c->status[i].details); + GRPC_MDSTR_UNREF(exec_ctx, c->status[i].details); } } for (ii = 0; ii < c->send_extra_metadata_count; ii++) { - GRPC_MDELEM_UNREF(c->send_extra_metadata[ii].md); + GRPC_MDELEM_UNREF(exec_ctx, c->send_extra_metadata[ii].md); } for (i = 0; i < GRPC_CONTEXT_COUNT; i++) { if (c->context[i].destroy) { @@ -446,22 +446,22 @@ static void set_status_code(grpc_call *call, status_source source, call->status[source].code = (grpc_status_code)status; } -static void set_status_details(grpc_call *call, status_source source, - grpc_mdstr *status) { +static void set_status_details(grpc_exec_ctx *exec_ctx, grpc_call *call, + status_source source, grpc_mdstr *status) { if (call->status[source].details != NULL) { - GRPC_MDSTR_UNREF(status); + GRPC_MDSTR_UNREF(exec_ctx, status); } else { call->status[source].details = status; } } -static void set_status_from_error(grpc_call *call, status_source source, - grpc_error *error) { +static void set_status_from_error(grpc_exec_ctx *exec_ctx, grpc_call *call, + status_source source, grpc_error *error) { grpc_status_code status; const char *msg; grpc_error_get_status(error, &status, &msg); set_status_code(call, source, (uint32_t)status); - set_status_details(call, source, grpc_mdstr_from_string(msg)); + set_status_details(exec_ctx, call, source, grpc_mdstr_from_string(msg)); } static void set_incoming_compression_algorithm( @@ -495,7 +495,8 @@ uint32_t grpc_call_test_only_get_message_flags(grpc_call *call) { static void destroy_encodings_accepted_by_peer(void *p) { return; } -static void set_encodings_accepted_by_peer(grpc_call *call, grpc_mdelem *mdel) { +static void set_encodings_accepted_by_peer(grpc_exec_ctx *exec_ctx, + grpc_call *call, grpc_mdelem *mdel) { size_t i; grpc_compression_algorithm algorithm; grpc_slice_buffer accept_encoding_parts; @@ -535,7 +536,7 @@ static void set_encodings_accepted_by_peer(grpc_call *call, grpc_mdelem *mdel) { } } - grpc_slice_buffer_destroy(&accept_encoding_parts); + grpc_slice_buffer_destroy_internal(exec_ctx, &accept_encoding_parts); grpc_mdelem_set_user_data( mdel, destroy_encodings_accepted_by_peer, @@ -593,12 +594,10 @@ static grpc_metadata *get_md_elem(grpc_metadata *metadata, return res; } -static int prepare_application_metadata(grpc_call *call, int count, - grpc_metadata *metadata, - int is_trailing, - int prepend_extra_metadata, - grpc_metadata *additional_metadata, - int additional_metadata_count) { +static int prepare_application_metadata( + grpc_exec_ctx *exec_ctx, grpc_call *call, int count, + grpc_metadata *metadata, int is_trailing, int prepend_extra_metadata, + grpc_metadata *additional_metadata, int additional_metadata_count) { int total_count = count + additional_metadata_count; int i; grpc_metadata_batch *batch = @@ -609,7 +608,7 @@ static int prepare_application_metadata(grpc_call *call, int count, grpc_linked_mdelem *l = (grpc_linked_mdelem *)&md->internal_data; GPR_ASSERT(sizeof(grpc_linked_mdelem) == sizeof(md->internal_data)); l->md = grpc_mdelem_from_string_and_buffer( - md->key, (const uint8_t *)md->value, md->value_length); + exec_ctx, md->key, (const uint8_t *)md->value, md->value_length); if (!grpc_header_key_is_legal(grpc_mdstr_as_c_string(l->md->key), GRPC_MDSTR_LENGTH(l->md->key))) { gpr_log(GPR_ERROR, "attempt to send invalid metadata key: %s", @@ -629,7 +628,7 @@ static int prepare_application_metadata(grpc_call *call, int count, const grpc_metadata *md = get_md_elem(metadata, additional_metadata, j, count); grpc_linked_mdelem *l = (grpc_linked_mdelem *)&md->internal_data; - GRPC_MDELEM_UNREF(l->md); + GRPC_MDELEM_UNREF(exec_ctx, l->md); } return 0; } @@ -811,7 +810,8 @@ static void send_close(grpc_exec_ctx *exec_ctx, void *tcp, grpc_error *error) { static grpc_call_error terminate_with_status(grpc_exec_ctx *exec_ctx, termination_closure *tc) { - set_status_from_error(tc->call, STATUS_FROM_API_OVERRIDE, tc->error); + set_status_from_error(exec_ctx, tc->call, STATUS_FROM_API_OVERRIDE, + tc->error); if (tc->type == TC_CANCEL) { grpc_closure_init(&tc->closure, send_cancel, tc); @@ -928,7 +928,8 @@ static grpc_compression_algorithm decode_compression(grpc_mdelem *md) { return algorithm; } -static grpc_mdelem *recv_common_filter(grpc_call *call, grpc_mdelem *elem) { +static grpc_mdelem *recv_common_filter(grpc_exec_ctx *exec_ctx, grpc_call *call, + grpc_mdelem *elem) { if (elem->key == GRPC_MDSTR_GRPC_STATUS) { GPR_TIMER_BEGIN("status", 0); set_status_code(call, STATUS_FROM_WIRE, decode_status(elem)); @@ -936,7 +937,8 @@ static grpc_mdelem *recv_common_filter(grpc_call *call, grpc_mdelem *elem) { return NULL; } else if (elem->key == GRPC_MDSTR_GRPC_MESSAGE) { GPR_TIMER_BEGIN("status-details", 0); - set_status_details(call, STATUS_FROM_WIRE, GRPC_MDSTR_REF(elem->value)); + set_status_details(exec_ctx, call, STATUS_FROM_WIRE, + GRPC_MDSTR_REF(elem->value)); GPR_TIMER_END("status-details", 0); return NULL; } @@ -962,9 +964,10 @@ static grpc_mdelem *publish_app_metadata(grpc_call *call, grpc_mdelem *elem, return elem; } -static grpc_mdelem *recv_initial_filter(void *callp, grpc_mdelem *elem) { - grpc_call *call = callp; - elem = recv_common_filter(call, elem); +static grpc_mdelem *recv_initial_filter(grpc_exec_ctx *exec_ctx, void *args, + grpc_mdelem *elem) { + grpc_call *call = args; + elem = recv_common_filter(exec_ctx, call, elem); if (elem == NULL) { return NULL; } else if (elem->key == GRPC_MDSTR_GRPC_ENCODING) { @@ -974,7 +977,7 @@ static grpc_mdelem *recv_initial_filter(void *callp, grpc_mdelem *elem) { return NULL; } else if (elem->key == GRPC_MDSTR_GRPC_ACCEPT_ENCODING) { GPR_TIMER_BEGIN("encodings_accepted_by_peer", 0); - set_encodings_accepted_by_peer(call, elem); + set_encodings_accepted_by_peer(exec_ctx, call, elem); GPR_TIMER_END("encodings_accepted_by_peer", 0); return NULL; } else { @@ -982,9 +985,10 @@ static grpc_mdelem *recv_initial_filter(void *callp, grpc_mdelem *elem) { } } -static grpc_mdelem *recv_trailing_filter(void *callp, grpc_mdelem *elem) { - grpc_call *call = callp; - elem = recv_common_filter(call, elem); +static grpc_mdelem *recv_trailing_filter(grpc_exec_ctx *exec_ctx, void *args, + grpc_mdelem *elem) { + grpc_call *call = args; + elem = recv_common_filter(exec_ctx, call, elem); if (elem == NULL) { return NULL; } else { @@ -1234,7 +1238,7 @@ static void receiving_initial_metadata_ready(grpc_exec_ctx *exec_ctx, if (error == GRPC_ERROR_NONE) { grpc_metadata_batch *md = &call->metadata_batch[1 /* is_receiving */][0 /* is_trailing */]; - grpc_metadata_batch_filter(md, recv_initial_filter, call); + grpc_metadata_batch_filter(exec_ctx, md, recv_initial_filter, call); GPR_TIMER_BEGIN("validate_filtered_metadata", 0); validate_filtered_metadata(exec_ctx, bctl); @@ -1278,14 +1282,15 @@ static void finish_batch(grpc_exec_ctx *exec_ctx, void *bctlp, intptr_t status; if (error != GRPC_ERROR_NONE && grpc_error_get_int(error, GRPC_ERROR_INT_GRPC_STATUS, &status)) { - set_status_from_error(call, STATUS_FROM_CORE, error); + set_status_from_error(exec_ctx, call, STATUS_FROM_CORE, error); } if (bctl->send_initial_metadata) { if (error != GRPC_ERROR_NONE) { - set_status_from_error(call, STATUS_FROM_CORE, error); + set_status_from_error(exec_ctx, call, STATUS_FROM_CORE, error); } grpc_metadata_batch_destroy( + exec_ctx, &call->metadata_batch[0 /* is_receiving */][0 /* is_trailing */]); } if (bctl->send_message) { @@ -1293,12 +1298,13 @@ static void finish_batch(grpc_exec_ctx *exec_ctx, void *bctlp, } if (bctl->send_final_op) { grpc_metadata_batch_destroy( + exec_ctx, &call->metadata_batch[0 /* is_receiving */][1 /* is_trailing */]); } if (bctl->recv_final_op) { grpc_metadata_batch *md = &call->metadata_batch[1 /* is_receiving */][1 /* is_trailing */]; - grpc_metadata_batch_filter(md, recv_trailing_filter, call); + grpc_metadata_batch_filter(exec_ctx, md, recv_trailing_filter, call); call->received_final_op = true; /* propagate cancellation to any interested children */ @@ -1435,7 +1441,7 @@ static grpc_call_error call_start_batch(grpc_exec_ctx *exec_ctx, bctl->send_initial_metadata = 1; call->sent_initial_metadata = 1; if (!prepare_application_metadata( - call, (int)op->data.send_initial_metadata.count, + exec_ctx, call, (int)op->data.send_initial_metadata.count, op->data.send_initial_metadata.metadata, 0, call->is_client, &compression_md, (int)additional_metadata_count)) { error = GRPC_CALL_ERROR_INVALID_METADATA; @@ -1515,15 +1521,15 @@ static grpc_call_error call_start_batch(grpc_exec_ctx *exec_ctx, call->sent_final_op = 1; call->send_extra_metadata_count = 1; call->send_extra_metadata[0].md = grpc_channel_get_reffed_status_elem( - call->channel, op->data.send_status_from_server.status); + exec_ctx, call->channel, op->data.send_status_from_server.status); if (op->data.send_status_from_server.status_details != NULL) { call->send_extra_metadata[1].md = grpc_mdelem_from_metadata_strings( - GRPC_MDSTR_GRPC_MESSAGE, + exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, grpc_mdstr_from_string( op->data.send_status_from_server.status_details)); call->send_extra_metadata_count++; set_status_details( - call, STATUS_FROM_API_OVERRIDE, + exec_ctx, call, STATUS_FROM_API_OVERRIDE, GRPC_MDSTR_REF(call->send_extra_metadata[1].md->value)); } if (op->data.send_status_from_server.status != GRPC_STATUS_OK) { @@ -1531,7 +1537,7 @@ static grpc_call_error call_start_batch(grpc_exec_ctx *exec_ctx, (uint32_t)op->data.send_status_from_server.status); } if (!prepare_application_metadata( - call, + exec_ctx, call, (int)op->data.send_status_from_server.trailing_metadata_count, op->data.send_status_from_server.trailing_metadata, 1, 1, NULL, 0)) { @@ -1660,7 +1666,7 @@ done_with_error: /* reverse any mutations that occured */ if (bctl->send_initial_metadata) { call->sent_initial_metadata = 0; - grpc_metadata_batch_clear(&call->metadata_batch[0][0]); + grpc_metadata_batch_clear(exec_ctx, &call->metadata_batch[0][0]); } if (bctl->send_message) { call->sending_message = 0; @@ -1668,7 +1674,7 @@ done_with_error: } if (bctl->send_final_op) { call->sent_final_op = 0; - grpc_metadata_batch_clear(&call->metadata_batch[0][1]); + grpc_metadata_batch_clear(exec_ctx, &call->metadata_batch[0][1]); } if (bctl->recv_initial_metadata) { call->received_initial_metadata = 0; diff --git a/src/core/lib/surface/call.h b/src/core/lib/surface/call.h index 18af41b7fb..233340c329 100644 --- a/src/core/lib/surface/call.h +++ b/src/core/lib/surface/call.h @@ -70,7 +70,8 @@ typedef struct grpc_call_create_args { /* Create a new call based on \a args. Regardless of success or failure, always returns a valid new call into *call */ -grpc_error *grpc_call_create(const grpc_call_create_args *args, +grpc_error *grpc_call_create(grpc_exec_ctx *exec_ctx, + const grpc_call_create_args *args, grpc_call **call); void grpc_call_set_completion_queue(grpc_exec_ctx *exec_ctx, grpc_call *call, diff --git a/src/core/lib/surface/channel.c b/src/core/lib/surface/channel.c index 9405015c50..b87295786e 100644 --- a/src/core/lib/surface/channel.c +++ b/src/core/lib/surface/channel.c @@ -87,11 +87,12 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target, grpc_channel_stack_type channel_stack_type, grpc_transport *optional_transport) { grpc_channel_stack_builder *builder = grpc_channel_stack_builder_create(); - grpc_channel_stack_builder_set_channel_arguments(builder, input_args); + grpc_channel_stack_builder_set_channel_arguments(exec_ctx, builder, + input_args); grpc_channel_stack_builder_set_target(builder, target); grpc_channel_stack_builder_set_transport(builder, optional_transport); if (!grpc_channel_init_create_stack(exec_ctx, builder, channel_stack_type)) { - grpc_channel_stack_builder_destroy(builder); + grpc_channel_stack_builder_destroy(exec_ctx, builder); return NULL; } grpc_channel_args *args = grpc_channel_args_copy( @@ -124,10 +125,10 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target, } else { if (channel->default_authority) { /* setting this takes precedence over anything else */ - GRPC_MDELEM_UNREF(channel->default_authority); + GRPC_MDELEM_UNREF(exec_ctx, channel->default_authority); } - channel->default_authority = - grpc_mdelem_from_strings(":authority", args->args[i].value.string); + channel->default_authority = grpc_mdelem_from_strings( + exec_ctx, ":authority", args->args[i].value.string); } } else if (0 == strcmp(args->args[i].key, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG)) { @@ -142,7 +143,7 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG); } else { channel->default_authority = grpc_mdelem_from_strings( - ":authority", args->args[i].value.string); + exec_ctx, ":authority", args->args[i].value.string); } } } else if (0 == strcmp(args->args[i].key, @@ -169,7 +170,7 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target, } done: - grpc_channel_args_destroy(args); + grpc_channel_args_destroy(exec_ctx, args); return channel; } @@ -188,10 +189,10 @@ void grpc_channel_get_info(grpc_channel *channel, } static grpc_call *grpc_channel_create_call_internal( - grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask, - grpc_completion_queue *cq, grpc_pollset_set *pollset_set_alternative, - grpc_mdelem *path_mdelem, grpc_mdelem *authority_mdelem, - gpr_timespec deadline) { + grpc_exec_ctx *exec_ctx, grpc_channel *channel, grpc_call *parent_call, + uint32_t propagation_mask, grpc_completion_queue *cq, + grpc_pollset_set *pollset_set_alternative, grpc_mdelem *path_mdelem, + grpc_mdelem *authority_mdelem, gpr_timespec deadline) { grpc_mdelem *send_metadata[2]; size_t num_metadata = 0; @@ -218,7 +219,7 @@ static grpc_call *grpc_channel_create_call_internal( args.send_deadline = deadline; grpc_call *call; - GRPC_LOG_IF_ERROR("call_create", grpc_call_create(&args, &call)); + GRPC_LOG_IF_ERROR("call_create", grpc_call_create(exec_ctx, &args, &call)); return call; } @@ -239,26 +240,30 @@ grpc_call *grpc_channel_create_call(grpc_channel *channel, (channel, parent_call, (unsigned)propagation_mask, cq, method, host, deadline.tv_sec, deadline.tv_nsec, (int)deadline.clock_type, reserved)); GPR_ASSERT(!reserved); - return grpc_channel_create_call_internal( - channel, parent_call, propagation_mask, cq, NULL, - grpc_mdelem_from_metadata_strings(GRPC_MDSTR_PATH, + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_call *call = grpc_channel_create_call_internal( + &exec_ctx, channel, parent_call, propagation_mask, cq, NULL, + grpc_mdelem_from_metadata_strings(&exec_ctx, GRPC_MDSTR_PATH, grpc_mdstr_from_string(method)), - host ? grpc_mdelem_from_metadata_strings(GRPC_MDSTR_AUTHORITY, + host ? grpc_mdelem_from_metadata_strings(&exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_mdstr_from_string(host)) : NULL, deadline); + grpc_exec_ctx_finish(&exec_ctx); + return call; } grpc_call *grpc_channel_create_pollset_set_call( - grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask, - grpc_pollset_set *pollset_set, const char *method, const char *host, - gpr_timespec deadline, void *reserved) { + grpc_exec_ctx *exec_ctx, grpc_channel *channel, grpc_call *parent_call, + uint32_t propagation_mask, grpc_pollset_set *pollset_set, + const char *method, const char *host, gpr_timespec deadline, + void *reserved) { GPR_ASSERT(!reserved); return grpc_channel_create_call_internal( - channel, parent_call, propagation_mask, NULL, pollset_set, - grpc_mdelem_from_metadata_strings(GRPC_MDSTR_PATH, + exec_ctx, channel, parent_call, propagation_mask, NULL, pollset_set, + grpc_mdelem_from_metadata_strings(exec_ctx, GRPC_MDSTR_PATH, grpc_mdstr_from_string(method)), - host ? grpc_mdelem_from_metadata_strings(GRPC_MDSTR_AUTHORITY, + host ? grpc_mdelem_from_metadata_strings(exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_mdstr_from_string(host)) : NULL, deadline); @@ -271,15 +276,18 @@ void *grpc_channel_register_call(grpc_channel *channel, const char *method, "grpc_channel_register_call(channel=%p, method=%s, host=%s, reserved=%p)", 4, (channel, method, host, reserved)); GPR_ASSERT(!reserved); - rc->path = grpc_mdelem_from_metadata_strings(GRPC_MDSTR_PATH, + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + rc->path = grpc_mdelem_from_metadata_strings(&exec_ctx, GRPC_MDSTR_PATH, grpc_mdstr_from_string(method)); - rc->authority = host ? grpc_mdelem_from_metadata_strings( - GRPC_MDSTR_AUTHORITY, grpc_mdstr_from_string(host)) - : NULL; + rc->authority = + host ? grpc_mdelem_from_metadata_strings(&exec_ctx, GRPC_MDSTR_AUTHORITY, + grpc_mdstr_from_string(host)) + : NULL; gpr_mu_lock(&channel->registered_call_mu); rc->next = channel->registered_calls; channel->registered_calls = rc; gpr_mu_unlock(&channel->registered_call_mu); + grpc_exec_ctx_finish(&exec_ctx); return rc; } @@ -299,10 +307,13 @@ grpc_call *grpc_channel_create_registered_call( registered_call_handle, deadline.tv_sec, deadline.tv_nsec, (int)deadline.clock_type, reserved)); GPR_ASSERT(!reserved); - return grpc_channel_create_call_internal( - channel, parent_call, propagation_mask, completion_queue, NULL, + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_call *call = grpc_channel_create_call_internal( + &exec_ctx, channel, parent_call, propagation_mask, completion_queue, NULL, GRPC_MDELEM_REF(rc->path), rc->authority ? GRPC_MDELEM_REF(rc->authority) : NULL, deadline); + grpc_exec_ctx_finish(&exec_ctx); + return call; } #ifdef GRPC_STREAM_REFCOUNT_DEBUG @@ -328,14 +339,14 @@ static void destroy_channel(grpc_exec_ctx *exec_ctx, void *arg, while (channel->registered_calls) { registered_call *rc = channel->registered_calls; channel->registered_calls = rc->next; - GRPC_MDELEM_UNREF(rc->path); + GRPC_MDELEM_UNREF(exec_ctx, rc->path); if (rc->authority) { - GRPC_MDELEM_UNREF(rc->authority); + GRPC_MDELEM_UNREF(exec_ctx, rc->authority); } gpr_free(rc); } if (channel->default_authority != NULL) { - GRPC_MDELEM_UNREF(channel->default_authority); + GRPC_MDELEM_UNREF(exec_ctx, channel->default_authority); } gpr_mu_destroy(&channel->registered_call_mu); gpr_free(channel->target); @@ -365,7 +376,8 @@ grpc_compression_options grpc_channel_compression_options( return channel->compression_options; } -grpc_mdelem *grpc_channel_get_reffed_status_elem(grpc_channel *channel, int i) { +grpc_mdelem *grpc_channel_get_reffed_status_elem(grpc_exec_ctx *exec_ctx, + grpc_channel *channel, int i) { char tmp[GPR_LTOA_MIN_BUFSIZE]; switch (i) { case 0: @@ -376,6 +388,6 @@ grpc_mdelem *grpc_channel_get_reffed_status_elem(grpc_channel *channel, int i) { return GRPC_MDELEM_GRPC_STATUS_2; } gpr_ltoa(i, tmp); - return grpc_mdelem_from_metadata_strings(GRPC_MDSTR_GRPC_STATUS, + return grpc_mdelem_from_metadata_strings(exec_ctx, GRPC_MDSTR_GRPC_STATUS, grpc_mdstr_from_string(tmp)); } diff --git a/src/core/lib/surface/channel.h b/src/core/lib/surface/channel.h index 23cc8656ca..2ebadb7a15 100644 --- a/src/core/lib/surface/channel.h +++ b/src/core/lib/surface/channel.h @@ -51,9 +51,10 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target, properties from the server call to this new client call, depending on the value of \a propagation_mask (see propagation_bits.h for possible values) */ grpc_call *grpc_channel_create_pollset_set_call( - grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask, - grpc_pollset_set *pollset_set, const char *method, const char *host, - gpr_timespec deadline, void *reserved); + grpc_exec_ctx *exec_ctx, grpc_channel *channel, grpc_call *parent_call, + uint32_t propagation_mask, grpc_pollset_set *pollset_set, + const char *method, const char *host, gpr_timespec deadline, + void *reserved); /** Get a (borrowed) pointer to this channels underlying channel stack */ grpc_channel_stack *grpc_channel_get_channel_stack(grpc_channel *channel); @@ -62,7 +63,8 @@ grpc_channel_stack *grpc_channel_get_channel_stack(grpc_channel *channel); status_code. The returned elem is owned by the caller. */ -grpc_mdelem *grpc_channel_get_reffed_status_elem(grpc_channel *channel, +grpc_mdelem *grpc_channel_get_reffed_status_elem(grpc_exec_ctx *exec_ctx, + grpc_channel *channel, int status_code); #ifdef GRPC_STREAM_REFCOUNT_DEBUG diff --git a/src/core/lib/surface/channel_init.c b/src/core/lib/surface/channel_init.c index 0627b34479..7acb444d9b 100644 --- a/src/core/lib/surface/channel_init.c +++ b/src/core/lib/surface/channel_init.c @@ -131,7 +131,7 @@ bool grpc_channel_init_create_stack(grpc_exec_ctx *exec_ctx, for (size_t i = 0; i < g_slots[type].num_slots; i++) { const stage_slot *slot = &g_slots[type].slots[i]; - if (!slot->fn(builder, slot->arg)) { + if (!slot->fn(exec_ctx, builder, slot->arg)) { return false; } } diff --git a/src/core/lib/surface/channel_init.h b/src/core/lib/surface/channel_init.h index b53f2aefb9..411f5eae18 100644 --- a/src/core/lib/surface/channel_init.h +++ b/src/core/lib/surface/channel_init.h @@ -51,7 +51,8 @@ extern "C" { /// One stage of mutation: call functions against \a builder to influence the /// finally constructed channel stack -typedef bool (*grpc_channel_init_stage)(grpc_channel_stack_builder *builder, +typedef bool (*grpc_channel_init_stage)(grpc_exec_ctx *exec_ctx, + grpc_channel_stack_builder *builder, void *arg); /// Global initialization of the system diff --git a/src/core/lib/surface/init.c b/src/core/lib/surface/init.c index 7903f57a68..e20e602547 100644 --- a/src/core/lib/surface/init.c +++ b/src/core/lib/surface/init.c @@ -80,17 +80,20 @@ static void do_basic_init(void) { g_initializations = 0; } -static bool append_filter(grpc_channel_stack_builder *builder, void *arg) { +static bool append_filter(grpc_exec_ctx *exec_ctx, + grpc_channel_stack_builder *builder, void *arg) { return grpc_channel_stack_builder_append_filter( builder, (const grpc_channel_filter *)arg, NULL, NULL); } -static bool prepend_filter(grpc_channel_stack_builder *builder, void *arg) { +static bool prepend_filter(grpc_exec_ctx *exec_ctx, + grpc_channel_stack_builder *builder, void *arg) { return grpc_channel_stack_builder_prepend_filter( builder, (const grpc_channel_filter *)arg, NULL, NULL); } -static bool maybe_add_http_filter(grpc_channel_stack_builder *builder, +static bool maybe_add_http_filter(grpc_exec_ctx *exec_ctx, + grpc_channel_stack_builder *builder, void *arg) { grpc_transport *t = grpc_channel_stack_builder_get_transport(builder); if (t && strstr(t->vtable->name, "http")) { @@ -221,11 +224,12 @@ void grpc_init(void) { void grpc_shutdown(void) { int i; GRPC_API_TRACE("grpc_shutdown(void)", 0, ()); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_mu_lock(&g_init_mu); if (--g_initializations == 0) { - grpc_executor_shutdown(); + grpc_executor_shutdown(&exec_ctx); grpc_cq_global_shutdown(); - grpc_iomgr_shutdown(); + grpc_iomgr_shutdown(&exec_ctx); gpr_timers_global_destroy(); grpc_tracer_shutdown(); for (i = g_number_of_plugins; i >= 0; i--) { @@ -233,9 +237,10 @@ void grpc_shutdown(void) { g_all_of_the_plugins[i].destroy(); } } - grpc_mdctx_global_shutdown(); + grpc_mdctx_global_shutdown(&exec_ctx); } gpr_mu_unlock(&g_init_mu); + grpc_exec_ctx_finish(&exec_ctx); } int grpc_is_initialized(void) { diff --git a/src/core/lib/surface/init_secure.c b/src/core/lib/surface/init_secure.c index 7ee7b51568..520a8aa84f 100644 --- a/src/core/lib/surface/init_secure.c +++ b/src/core/lib/surface/init_secure.c @@ -50,7 +50,7 @@ void grpc_security_pre_init(void) { } static bool maybe_prepend_client_auth_filter( - grpc_channel_stack_builder *builder, void *arg) { + grpc_exec_ctx *exec_ctx, grpc_channel_stack_builder *builder, void *arg) { const grpc_channel_args *args = grpc_channel_stack_builder_get_channel_arguments(builder); if (args) { @@ -65,7 +65,7 @@ static bool maybe_prepend_client_auth_filter( } static bool maybe_prepend_server_auth_filter( - grpc_channel_stack_builder *builder, void *arg) { + grpc_exec_ctx *exec_ctx, grpc_channel_stack_builder *builder, void *arg) { const grpc_channel_args *args = grpc_channel_stack_builder_get_channel_arguments(builder); if (args) { diff --git a/src/core/lib/surface/lame_client.c b/src/core/lib/surface/lame_client.c index 57da94ac1e..2d56211716 100644 --- a/src/core/lib/surface/lame_client.c +++ b/src/core/lib/surface/lame_client.c @@ -55,14 +55,15 @@ typedef struct { const char *error_message; } channel_data; -static void fill_metadata(grpc_call_element *elem, grpc_metadata_batch *mdb) { +static void fill_metadata(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, + grpc_metadata_batch *mdb) { call_data *calld = elem->call_data; channel_data *chand = elem->channel_data; char tmp[GPR_LTOA_MIN_BUFSIZE]; gpr_ltoa(chand->error_code, tmp); - calld->status.md = grpc_mdelem_from_strings("grpc-status", tmp); + calld->status.md = grpc_mdelem_from_strings(exec_ctx, "grpc-status", tmp); calld->details.md = - grpc_mdelem_from_strings("grpc-message", chand->error_message); + grpc_mdelem_from_strings(exec_ctx, "grpc-message", chand->error_message); calld->status.prev = calld->details.next = NULL; calld->status.next = &calld->details; calld->details.prev = &calld->status; @@ -76,9 +77,9 @@ static void lame_start_transport_stream_op(grpc_exec_ctx *exec_ctx, grpc_transport_stream_op *op) { GRPC_CALL_LOG_OP(GPR_INFO, elem, op); if (op->recv_initial_metadata != NULL) { - fill_metadata(elem, op->recv_initial_metadata); + fill_metadata(exec_ctx, elem, op->recv_initial_metadata); } else if (op->recv_trailing_metadata != NULL) { - fill_metadata(elem, op->recv_trailing_metadata); + fill_metadata(exec_ctx, elem, op->recv_trailing_metadata); } grpc_transport_stream_op_finish_with_failure( exec_ctx, op, GRPC_ERROR_CREATE("lame client channel")); diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c index 62d7afc8da..332098dc1f 100644 --- a/src/core/lib/surface/server.c +++ b/src/core/lib/surface/server.c @@ -45,6 +45,7 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/iomgr/iomgr.h" +#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/support/stack_lockfree.h" #include "src/core/lib/support/string.h" #include "src/core/lib/surface/api_trace.h" @@ -271,7 +272,7 @@ struct shutdown_cleanup_args { static void shutdown_cleanup(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { struct shutdown_cleanup_args *a = arg; - grpc_slice_unref(a->slice); + grpc_slice_unref_internal(exec_ctx, a->slice); gpr_free(a); } @@ -379,7 +380,7 @@ static void server_ref(grpc_server *server) { static void server_delete(grpc_exec_ctx *exec_ctx, grpc_server *server) { registered_method *rm; size_t i; - grpc_channel_args_destroy(server->channel_args); + grpc_channel_args_destroy(exec_ctx, server->channel_args); gpr_mu_destroy(&server->mu_global); gpr_mu_destroy(&server->mu_call); while ((rm = server->registered_methods) != NULL) { @@ -740,7 +741,8 @@ static void maybe_finish_shutdown(grpc_exec_ctx *exec_ctx, } } -static grpc_mdelem *server_filter(void *user_data, grpc_mdelem *md) { +static grpc_mdelem *server_filter(grpc_exec_ctx *exec_ctx, void *user_data, + grpc_mdelem *md) { grpc_call_element *elem = user_data; call_data *calld = elem->call_data; if (md->key == GRPC_MDSTR_PATH) { @@ -764,7 +766,8 @@ static void server_on_recv_initial_metadata(grpc_exec_ctx *exec_ctx, void *ptr, gpr_timespec op_deadline; GRPC_ERROR_REF(error); - grpc_metadata_batch_filter(calld->recv_initial_metadata, server_filter, elem); + grpc_metadata_batch_filter(exec_ctx, calld->recv_initial_metadata, + server_filter, elem); op_deadline = calld->recv_initial_metadata->deadline; if (0 != gpr_time_cmp(op_deadline, gpr_inf_future(op_deadline.clock_type))) { calld->deadline = op_deadline; @@ -838,7 +841,7 @@ static void accept_stream(grpc_exec_ctx *exec_ctx, void *cd, args.server_transport_data = transport_server_data; args.send_deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC); grpc_call *call; - grpc_error *error = grpc_call_create(&args, &call); + grpc_error *error = grpc_call_create(exec_ctx, &args, &call); grpc_call_element *elem = grpc_call_stack_element(grpc_call_get_call_stack(call), 0); if (error != GRPC_ERROR_NONE) { @@ -902,10 +905,10 @@ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, GPR_ASSERT(calld->state != PENDING); if (calld->host) { - GRPC_MDSTR_UNREF(calld->host); + GRPC_MDSTR_UNREF(exec_ctx, calld->host); } if (calld->path) { - GRPC_MDSTR_UNREF(calld->path); + GRPC_MDSTR_UNREF(exec_ctx, calld->path); } grpc_metadata_array_destroy(&calld->initial_metadata); @@ -937,10 +940,10 @@ static void destroy_channel_elem(grpc_exec_ctx *exec_ctx, if (chand->registered_methods) { for (i = 0; i < chand->registered_method_slots; i++) { if (chand->registered_methods[i].method) { - GRPC_MDSTR_UNREF(chand->registered_methods[i].method); + GRPC_MDSTR_UNREF(exec_ctx, chand->registered_methods[i].method); } if (chand->registered_methods[i].host) { - GRPC_MDSTR_UNREF(chand->registered_methods[i].host); + GRPC_MDSTR_UNREF(exec_ctx, chand->registered_methods[i].host); } } gpr_free(chand->registered_methods); |