diff options
author | Craig Tiller <ctiller@google.com> | 2016-11-18 09:27:39 -0800 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2016-11-18 09:27:39 -0800 |
commit | e17029353010d0ef393d0feeb14df20321d6c984 (patch) | |
tree | 6e2a81f1635e926a90b17fad46a9c1a6237cacac | |
parent | 0160de9ae5c53222813c0030fc6d4a094d063d0a (diff) |
Progress towards mdelem pointer elimination
-rw-r--r-- | src/core/lib/surface/channel.c | 27 | ||||
-rw-r--r-- | src/core/lib/surface/server.c | 12 | ||||
-rw-r--r-- | src/core/lib/transport/metadata.c | 5 | ||||
-rw-r--r-- | src/core/lib/transport/metadata.h | 2 | ||||
-rw-r--r-- | src/core/lib/transport/metadata_batch.c | 16 |
5 files changed, 28 insertions, 34 deletions
diff --git a/src/core/lib/surface/channel.c b/src/core/lib/surface/channel.c index 7aabca8299..501545b5c0 100644 --- a/src/core/lib/surface/channel.c +++ b/src/core/lib/surface/channel.c @@ -119,7 +119,7 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target, gpr_log(GPR_ERROR, "%s ignored: it must be a string", GRPC_ARG_DEFAULT_AUTHORITY); } else { - if (channel->default_authority) { + if (!GRPC_MDISNULL(channel->default_authority)) { /* setting this takes precedence over anything else */ GRPC_MDELEM_UNREF(exec_ctx, channel->default_authority); } @@ -133,7 +133,7 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target, gpr_log(GPR_ERROR, "%s ignored: it must be a string", GRPC_SSL_TARGET_NAME_OVERRIDE_ARG); } else { - if (channel->default_authority) { + if (!GRPC_MDISNULL(channel->default_authority)) { /* other ways of setting this (notably ssl) take precedence */ gpr_log(GPR_ERROR, "%s ignored: default host already set some other way", @@ -199,9 +199,9 @@ static grpc_call *grpc_channel_create_call_internal( GPR_ASSERT(!(cq != NULL && pollset_set_alternative != NULL)); send_metadata[num_metadata++] = path_mdelem; - if (authority_mdelem != NULL) { + if (!GRPC_MDISNULL(authority_mdelem)) { send_metadata[num_metadata++] = authority_mdelem; - } else if (channel->default_authority != NULL) { + } else if (!GRPC_MDISNULL(channel->default_authority)) { send_metadata[num_metadata++] = GRPC_MDELEM_REF(channel->default_authority); } @@ -236,7 +236,7 @@ grpc_call *grpc_channel_create_call(grpc_channel *channel, grpc_slice_ref(method)), host != NULL ? grpc_mdelem_from_slices(&exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_slice_ref(*host)) - : NULL, + : GRPC_MDNULL, deadline); grpc_exec_ctx_finish(&exec_ctx); return call; @@ -253,7 +253,7 @@ grpc_call *grpc_channel_create_pollset_set_call( grpc_slice_ref(method)), host != NULL ? grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_slice_ref(*host)) - : NULL, + : GRPC_MDNULL, deadline); } @@ -273,7 +273,7 @@ void *grpc_channel_register_call(grpc_channel *channel, const char *method, host ? grpc_mdelem_from_slices( &exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_slice_intern(grpc_slice_from_copied_string(host))) - : NULL; + : GRPC_MDNULL; gpr_mu_lock(&channel->registered_call_mu); rc->next = channel->registered_calls; channel->registered_calls = rc; @@ -301,8 +301,7 @@ grpc_call *grpc_channel_create_registered_call( 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_MDELEM_REF(rc->path), GRPC_MDELEM_REF(rc->authority), deadline); grpc_exec_ctx_finish(&exec_ctx); return call; } @@ -331,14 +330,10 @@ static void destroy_channel(grpc_exec_ctx *exec_ctx, void *arg, registered_call *rc = channel->registered_calls; channel->registered_calls = rc->next; GRPC_MDELEM_UNREF(exec_ctx, rc->path); - if (rc->authority) { - GRPC_MDELEM_UNREF(exec_ctx, rc->authority); - } + GRPC_MDELEM_UNREF(exec_ctx, rc->authority); gpr_free(rc); } - if (channel->default_authority != NULL) { - GRPC_MDELEM_UNREF(exec_ctx, channel->default_authority); - } + GRPC_MDELEM_UNREF(exec_ctx, channel->default_authority); gpr_mu_destroy(&channel->registered_call_mu); gpr_free(channel->target); gpr_free(channel); @@ -368,7 +363,7 @@ grpc_compression_options grpc_channel_compression_options( } grpc_mdelem grpc_channel_get_reffed_status_elem(grpc_exec_ctx *exec_ctx, - grpc_channel *channel, int i) { + grpc_channel *channel, int i) { char tmp[GPR_LTOA_MIN_BUFSIZE]; switch (i) { case 0: diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c index d16ed92c18..c43a6ef4b3 100644 --- a/src/core/lib/surface/server.c +++ b/src/core/lib/surface/server.c @@ -739,16 +739,16 @@ 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 (grpc_slice_cmp(md->key, GRPC_MDSTR_PATH) == 0) { + if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_PATH) == 0) { if (!calld->path_set) { - calld->path = grpc_slice_ref(md->value); + calld->path = grpc_slice_ref(GRPC_MDVALUE(md)); } - return NULL; - } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_AUTHORITY) == 0) { + return GRPC_MDNULL; + } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_AUTHORITY) == 0) { if (!calld->host_set) { - calld->host = grpc_slice_ref(md->value); + calld->host = grpc_slice_ref(GRPC_MDVALUE(md)); } - return NULL; + return GRPC_MDNULL; } return md; } diff --git a/src/core/lib/transport/metadata.c b/src/core/lib/transport/metadata.c index 370d92d858..c114cf9a30 100644 --- a/src/core/lib/transport/metadata.c +++ b/src/core/lib/transport/metadata.c @@ -313,8 +313,8 @@ size_t grpc_mdelem_get_size_in_hpack_table(grpc_mdelem elem) { } grpc_mdelem grpc_mdelem_ref(grpc_mdelem gmd DEBUG_ARGS) { + if (gmd.payload == NULL || is_mdelem_static(gmd)) return gmd; internal_metadata *md = (internal_metadata *)gmd.payload; - if (is_mdelem_static(gmd)) return gmd; #ifdef GRPC_METADATA_REFCOUNT_DEBUG gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "ELM REF:%p:%zu->%zu: '%s' = '%s'", (void *)md, @@ -333,9 +333,8 @@ grpc_mdelem grpc_mdelem_ref(grpc_mdelem gmd DEBUG_ARGS) { } void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem gmd DEBUG_ARGS) { + if (gmd.payload == NULL || is_mdelem_static(gmd)) return; internal_metadata *md = (internal_metadata *)gmd.payload; - if (!md) return; - if (is_mdelem_static(gmd)) return; #ifdef GRPC_METADATA_REFCOUNT_DEBUG gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "ELM UNREF:%p:%zu->%zu: '%s' = '%s'", (void *)md, diff --git a/src/core/lib/transport/metadata.h b/src/core/lib/transport/metadata.h index cc109d5052..da5416bf76 100644 --- a/src/core/lib/transport/metadata.h +++ b/src/core/lib/transport/metadata.h @@ -127,7 +127,7 @@ void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem md); /* We add 32 bytes of padding as per RFC-7540 section 6.5.2. */ #define GRPC_MDELEM_LENGTH(e) \ - (GRPC_SLICE_LENGTH(GRPC_MDKEY((e))) + GRPC_SLICE_LENGTH(MRPC_MDVALUE((e))) + \ + (GRPC_SLICE_LENGTH(GRPC_MDKEY((e))) + GRPC_SLICE_LENGTH(GRPC_MDVALUE((e))) + \ 32) #define GRPC_MDSTR_KV_HASH(k_hash, v_hash) (GPR_ROTL((k_hash), 2) ^ (v_hash)) diff --git a/src/core/lib/transport/metadata_batch.c b/src/core/lib/transport/metadata_batch.c index 0cd92b0207..9e0a8fbbe1 100644 --- a/src/core/lib/transport/metadata_batch.c +++ b/src/core/lib/transport/metadata_batch.c @@ -52,7 +52,7 @@ static void assert_valid_list(grpc_mdelem_list *list) { GPR_ASSERT((list->head == list->tail) == (list->head->next == NULL)); for (l = list->head; l; l = l->next) { - GPR_ASSERT(l->md); + GPR_ASSERT(!GRPC_MDISNULL(l->md)); GPR_ASSERT((l->prev == NULL) == (l == list->head)); GPR_ASSERT((l->next == NULL) == (l == list->tail)); if (l->next) GPR_ASSERT(l->next->prev == l); @@ -83,14 +83,14 @@ void grpc_metadata_batch_destroy(grpc_exec_ctx *exec_ctx, void grpc_metadata_batch_add_head(grpc_metadata_batch *batch, grpc_linked_mdelem *storage, grpc_mdelem elem_to_add) { - GPR_ASSERT(elem_to_add); + GPR_ASSERT(!GRPC_MDISNULL(elem_to_add)); storage->md = elem_to_add; grpc_metadata_batch_link_head(batch, storage); } static void link_head(grpc_mdelem_list *list, grpc_linked_mdelem *storage) { assert_valid_list(list); - GPR_ASSERT(storage->md); + GPR_ASSERT(!GRPC_MDISNULL(storage->md)); storage->prev = NULL; storage->next = list->head; if (list->head != NULL) { @@ -110,14 +110,14 @@ void grpc_metadata_batch_link_head(grpc_metadata_batch *batch, void grpc_metadata_batch_add_tail(grpc_metadata_batch *batch, grpc_linked_mdelem *storage, grpc_mdelem elem_to_add) { - GPR_ASSERT(elem_to_add); + GPR_ASSERT(!GRPC_MDISNULL(elem_to_add)); storage->md = elem_to_add; grpc_metadata_batch_link_tail(batch, storage); } static void link_tail(grpc_mdelem_list *list, grpc_linked_mdelem *storage) { assert_valid_list(list); - GPR_ASSERT(storage->md); + GPR_ASSERT(!GRPC_MDISNULL(storage->md)); storage->prev = list->tail; storage->next = NULL; storage->reserved = NULL; @@ -157,7 +157,7 @@ void grpc_metadata_batch_filter(grpc_exec_ctx *exec_ctx, grpc_mdelem orig = l->md; grpc_mdelem filt = filter(exec_ctx, user_data, orig); next = l->next; - if (filt == NULL) { + if (GRPC_MDISNULL(filt)) { if (l->prev) { l->prev->next = l->next; } @@ -172,7 +172,7 @@ void grpc_metadata_batch_filter(grpc_exec_ctx *exec_ctx, } assert_valid_list(&batch->list); GRPC_MDELEM_UNREF(exec_ctx, l->md); - } else if (filt != orig) { + } else if (!grpc_mdelem_eq(filt, orig)) { GRPC_MDELEM_UNREF(exec_ctx, orig); l->md = filt; } @@ -184,7 +184,7 @@ void grpc_metadata_batch_filter(grpc_exec_ctx *exec_ctx, static grpc_mdelem no_metadata_for_you(grpc_exec_ctx *exec_ctx, void *user_data, grpc_mdelem elem) { - return NULL; + return GRPC_MDNULL; } void grpc_metadata_batch_clear(grpc_exec_ctx *exec_ctx, |