From 490dc0e66c3feaa7635cc00b1e60e6837cf47eb7 Mon Sep 17 00:00:00 2001 From: Hongwei Wang Date: Thu, 6 Aug 2015 18:48:19 -0700 Subject: [PATCH] Restore iomgr --- src/core/iomgr/iomgr.c | 21 ++--------------- src/core/iomgr/iomgr_internal.h | 15 ++---------- src/core/surface/channel.c | 42 ++++++++++++--------------------- 3 files changed, 19 insertions(+), 59 deletions(-) diff --git a/src/core/iomgr/iomgr.c b/src/core/iomgr/iomgr.c index ae2c455c98d..fdc9adf4af9 100644 --- a/src/core/iomgr/iomgr.c +++ b/src/core/iomgr/iomgr.c @@ -44,16 +44,6 @@ #include #include -#ifdef GRPC_IOMGR_REFCOUNT_DEBUG -static void iomgr_object_trace(const char *action, grpc_iomgr_object *obj, - const char *file, int line) { - gpr_log(GPR_DEBUG, "iomgr object %s: %p - %s from %s:%i", action, - obj, obj->name, file, line); -} -#else -#define iomgr_object_trace(action, obj, file, line) -#endif - static gpr_mu g_mu; static gpr_cv g_rcv; static grpc_iomgr_closure *g_cbs_head = NULL; @@ -194,12 +184,8 @@ void grpc_iomgr_shutdown(void) { gpr_cv_destroy(&g_rcv); } -void grpc_iomgr_register_object_internal(grpc_iomgr_object *obj, - const char *name, - const char *file, - int line) { +void grpc_iomgr_register_object(grpc_iomgr_object *obj, const char *name) { obj->name = gpr_strdup(name); - iomgr_object_trace("register", obj, file, line); gpr_mu_lock(&g_mu); obj->next = &g_root_object; obj->prev = obj->next->prev; @@ -207,10 +193,7 @@ void grpc_iomgr_register_object_internal(grpc_iomgr_object *obj, gpr_mu_unlock(&g_mu); } -void grpc_iomgr_unregister_object_internal(grpc_iomgr_object *obj, - const char *file, - int line) { - iomgr_object_trace("unregister", obj, file, line); +void grpc_iomgr_unregister_object(grpc_iomgr_object *obj) { gpr_mu_lock(&g_mu); obj->next->prev = obj->prev; obj->prev->next = obj->next; diff --git a/src/core/iomgr/iomgr_internal.h b/src/core/iomgr/iomgr_internal.h index d02be779bd5..6c1e0e1799e 100644 --- a/src/core/iomgr/iomgr_internal.h +++ b/src/core/iomgr/iomgr_internal.h @@ -46,19 +46,8 @@ typedef struct grpc_iomgr_object { int grpc_maybe_call_delayed_callbacks(gpr_mu *drop_mu, int success); void grpc_iomgr_add_delayed_callback(grpc_iomgr_closure *iocb, int success); -void grpc_iomgr_register_object_internal(grpc_iomgr_object *obj, - const char *name, - const char *file, - int line); -void grpc_iomgr_unregister_object_internal(grpc_iomgr_object *obj, - const char *file, - int line); - -#define grpc_iomgr_register_object(obj, name) \ - grpc_iomgr_register_object_internal(obj, name, __FILE__, __LINE__) - -#define grpc_iomgr_unregister_object(obj) \ - grpc_iomgr_unregister_object_internal(obj, __FILE__, __LINE__) +void grpc_iomgr_register_object(grpc_iomgr_object *obj, const char *name); +void grpc_iomgr_unregister_object(grpc_iomgr_object *obj); void grpc_iomgr_platform_init(void); void grpc_iomgr_platform_shutdown(void); diff --git a/src/core/surface/channel.c b/src/core/surface/channel.c index c87937f6695..583d3501287 100644 --- a/src/core/surface/channel.c +++ b/src/core/surface/channel.c @@ -104,8 +104,7 @@ grpc_channel *grpc_channel_create_from_filters( channel->grpc_status_string = grpc_mdstr_from_string(mdctx, "grpc-status", 0); channel->grpc_compression_algorithm_string = grpc_mdstr_from_string(mdctx, "grpc-encoding", 0); - channel->grpc_message_string = - grpc_mdstr_from_string(mdctx, "grpc-message", 0); + channel->grpc_message_string = grpc_mdstr_from_string(mdctx, "grpc-message", 0); for (i = 0; i < NUM_CACHED_STATUS_ELEMS; i++) { char buf[GPR_LTOA_MIN_BUFSIZE]; gpr_ltoa(i, buf); @@ -147,38 +146,31 @@ char *grpc_channel_get_target(grpc_channel *channel) { } static grpc_call *grpc_channel_create_call_internal( - grpc_channel *channel, grpc_call *parent_call, gpr_uint32 propagation_mask, - grpc_completion_queue *cq, grpc_mdelem *path_mdelem, + grpc_channel *channel, grpc_completion_queue *cq, grpc_mdelem *path_mdelem, grpc_mdelem *authority_mdelem, gpr_timespec deadline) { grpc_mdelem *send_metadata[2]; - int num_metadata = 0; GPR_ASSERT(channel->is_client); - send_metadata[num_metadata++] = path_mdelem; - if (authority_mdelem != NULL) { - send_metadata[num_metadata++] = authority_mdelem; - } + send_metadata[0] = path_mdelem; + send_metadata[1] = authority_mdelem; - return grpc_call_create(channel, parent_call, propagation_mask, cq, NULL, - send_metadata, num_metadata, deadline); + return grpc_call_create(channel, cq, NULL, send_metadata, + GPR_ARRAY_SIZE(send_metadata), deadline); } grpc_call *grpc_channel_create_call(grpc_channel *channel, - grpc_call *parent_call, - gpr_uint32 propagation_mask, grpc_completion_queue *cq, const char *method, const char *host, gpr_timespec deadline) { return grpc_channel_create_call_internal( - channel, parent_call, propagation_mask, cq, + channel, cq, grpc_mdelem_from_metadata_strings( channel->metadata_context, GRPC_MDSTR_REF(channel->path_string), grpc_mdstr_from_string(channel->metadata_context, method, 0)), - host ? grpc_mdelem_from_metadata_strings( channel->metadata_context, GRPC_MDSTR_REF(channel->authority_string), - grpc_mdstr_from_string(channel->metadata_context, host, 0)) : NULL, + grpc_mdstr_from_string(channel->metadata_context, host, 0)), deadline); } @@ -188,9 +180,9 @@ void *grpc_channel_register_call(grpc_channel *channel, const char *method, rc->path = grpc_mdelem_from_metadata_strings( channel->metadata_context, GRPC_MDSTR_REF(channel->path_string), grpc_mdstr_from_string(channel->metadata_context, method, 0)); - rc->authority = host ? grpc_mdelem_from_metadata_strings( + rc->authority = grpc_mdelem_from_metadata_strings( channel->metadata_context, GRPC_MDSTR_REF(channel->authority_string), - grpc_mdstr_from_string(channel->metadata_context, host, 0)) : NULL; + grpc_mdstr_from_string(channel->metadata_context, host, 0)); gpr_mu_lock(&channel->registered_call_mu); rc->next = channel->registered_calls; channel->registered_calls = rc; @@ -199,14 +191,12 @@ void *grpc_channel_register_call(grpc_channel *channel, const char *method, } grpc_call *grpc_channel_create_registered_call( - grpc_channel *channel, grpc_call *parent_call, gpr_uint32 propagation_mask, - grpc_completion_queue *completion_queue, void *registered_call_handle, - gpr_timespec deadline) { + grpc_channel *channel, grpc_completion_queue *completion_queue, + void *registered_call_handle, gpr_timespec deadline) { registered_call *rc = registered_call_handle; return grpc_channel_create_call_internal( - channel, parent_call, propagation_mask, completion_queue, - GRPC_MDELEM_REF(rc->path), - rc->authority ? GRPC_MDELEM_REF(rc->authority) : NULL, deadline); + channel, completion_queue, GRPC_MDELEM_REF(rc->path), + GRPC_MDELEM_REF(rc->authority), deadline); } #ifdef GRPC_CHANNEL_REF_COUNT_DEBUG @@ -235,9 +225,7 @@ static void destroy_channel(void *p, int ok) { registered_call *rc = channel->registered_calls; channel->registered_calls = rc->next; GRPC_MDELEM_UNREF(rc->path); - if (rc->authority) { - GRPC_MDELEM_UNREF(rc->authority); - } + GRPC_MDELEM_UNREF(rc->authority); gpr_free(rc); } grpc_mdctx_unref(channel->metadata_context);