Removed some unnecessary memset operations in core.

pull/18857/head
Arjun Roy 6 years ago
parent defcbda8b2
commit cf9301f964
  1. 3
      include/grpc/impl/codegen/grpc_types.h
  2. 12
      src/core/lib/surface/call.cc
  3. 1
      src/core/lib/surface/call_details.cc
  4. 14
      src/core/lib/surface/completion_queue.cc
  5. 5
      src/core/lib/surface/server.cc
  6. 1
      src/csharp/Grpc.Core.Tests/Internal/CompletionQueueSafeHandleTest.cs
  7. 5
      test/core/bad_connection/close_fd_test.cc

@ -494,7 +494,8 @@ typedef struct grpc_event {
field is guaranteed to be 0 */
int success;
/** The tag passed to grpc_call_start_batch etc to start this operation.
Only GRPC_OP_COMPLETE has a tag. */
*Only* GRPC_OP_COMPLETE has a tag. For all other grpc_completion_type
values, tag is uninitialized. */
void* tag;
} grpc_event;

@ -1557,7 +1557,10 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops,
goto done_with_error;
}
/* process compression level */
memset(&call->compression_md, 0, sizeof(call->compression_md));
grpc_metadata& compression_md = call->compression_md;
compression_md.key = grpc_empty_slice();
compression_md.value = grpc_empty_slice();
compression_md.flags = 0;
size_t additional_metadata_count = 0;
grpc_compression_level effective_compression_level =
GRPC_COMPRESS_LEVEL_NONE;
@ -1580,8 +1583,8 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops,
call, effective_compression_level);
/* the following will be picked up by the compress filter and used
* as the call's compression algorithm. */
call->compression_md.key = GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST;
call->compression_md.value = grpc_compression_algorithm_slice(calgo);
compression_md.key = GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST;
compression_md.value = grpc_compression_algorithm_slice(calgo);
additional_metadata_count++;
}
@ -1595,8 +1598,7 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops,
if (!prepare_application_metadata(
call, static_cast<int>(op->data.send_initial_metadata.count),
op->data.send_initial_metadata.metadata, 0, call->is_client,
&call->compression_md,
static_cast<int>(additional_metadata_count))) {
&compression_md, static_cast<int>(additional_metadata_count))) {
error = GRPC_CALL_ERROR_INVALID_METADATA;
goto done_with_error;
}

@ -29,7 +29,6 @@
void grpc_call_details_init(grpc_call_details* cd) {
GRPC_API_TRACE("grpc_call_details_init(cd=%p)", 1, (cd));
memset(cd, 0, sizeof(*cd));
cd->method = grpc_empty_slice();
cd->host = grpc_empty_slice();
}

@ -1002,15 +1002,15 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline,
continue;
}
memset(&ret, 0, sizeof(ret));
ret.type = GRPC_QUEUE_SHUTDOWN;
ret.success = 0;
break;
}
if (!is_finished_arg.first_loop &&
grpc_core::ExecCtx::Get()->Now() >= deadline_millis) {
memset(&ret, 0, sizeof(ret));
ret.type = GRPC_QUEUE_TIMEOUT;
ret.success = 0;
dump_pending_tags(cq);
break;
}
@ -1027,8 +1027,8 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline,
gpr_log(GPR_ERROR, "Completion queue next failed: %s", msg);
GRPC_ERROR_UNREF(err);
memset(&ret, 0, sizeof(ret));
ret.type = GRPC_QUEUE_TIMEOUT;
ret.success = 0;
dump_pending_tags(cq);
break;
}
@ -1234,8 +1234,8 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag,
}
if (cqd->shutdown.Load(grpc_core::MemoryOrder::RELAXED)) {
gpr_mu_unlock(cq->mu);
memset(&ret, 0, sizeof(ret));
ret.type = GRPC_QUEUE_SHUTDOWN;
ret.success = 0;
break;
}
if (!add_plucker(cq, tag, &worker)) {
@ -1244,9 +1244,9 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag,
"is %d",
GRPC_MAX_COMPLETION_QUEUE_PLUCKERS);
gpr_mu_unlock(cq->mu);
memset(&ret, 0, sizeof(ret));
/* TODO(ctiller): should we use a different result here */
ret.type = GRPC_QUEUE_TIMEOUT;
ret.success = 0;
dump_pending_tags(cq);
break;
}
@ -1254,8 +1254,8 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag,
grpc_core::ExecCtx::Get()->Now() >= deadline_millis) {
del_plucker(cq, tag, &worker);
gpr_mu_unlock(cq->mu);
memset(&ret, 0, sizeof(ret));
ret.type = GRPC_QUEUE_TIMEOUT;
ret.success = 0;
dump_pending_tags(cq);
break;
}
@ -1269,8 +1269,8 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag,
gpr_log(GPR_ERROR, "Completion queue pluck failed: %s", msg);
GRPC_ERROR_UNREF(err);
memset(&ret, 0, sizeof(ret));
ret.type = GRPC_QUEUE_TIMEOUT;
ret.success = 0;
dump_pending_tags(cq);
break;
}

@ -347,8 +347,8 @@ static void channel_broadcaster_shutdown(channel_broadcaster* cb,
*/
static void request_matcher_init(request_matcher* rm, grpc_server* server) {
memset(rm, 0, sizeof(*rm));
rm->server = server;
rm->pending_head = rm->pending_tail = nullptr;
rm->requests_per_cq = static_cast<gpr_locked_mpscq*>(
gpr_malloc(sizeof(*rm->requests_per_cq) * server->cq_count));
for (size_t i = 0; i < server->cq_count; i++) {
@ -601,8 +601,9 @@ static void finish_start_new_rpc(
break;
case GRPC_SRM_PAYLOAD_READ_INITIAL_BYTE_BUFFER: {
grpc_op op;
memset(&op, 0, sizeof(op));
op.op = GRPC_OP_RECV_MESSAGE;
op.flags = 0;
op.reserved = nullptr;
op.data.recv_message.recv_message = &calld->payload;
GRPC_CLOSURE_INIT(&calld->publish, publish_new_rpc, elem,
grpc_schedule_on_exec_ctx);

@ -47,7 +47,6 @@ namespace Grpc.Core.Internal.Tests
GrpcEnvironment.ReleaseAsync().Wait();
Assert.AreEqual(CompletionQueueEvent.CompletionType.Shutdown, ev.type);
Assert.AreNotEqual(IntPtr.Zero, ev.success);
Assert.AreEqual(IntPtr.Zero, ev.tag);
}
}
}

@ -328,7 +328,6 @@ static void _test_close_before_server_recv(fd_type fdtype) {
*/
if (event.type == GRPC_QUEUE_TIMEOUT) {
GPR_ASSERT(event.success == 0);
GPR_ASSERT(event.tag == nullptr);
/* status is not initialized */
GPR_ASSERT(status == GRPC_STATUS__DO_NOT_USE);
} else {
@ -531,7 +530,6 @@ static void _test_close_before_server_send(fd_type fdtype) {
} else {
GPR_ASSERT(event.type == GRPC_QUEUE_TIMEOUT);
GPR_ASSERT(event.success == 0);
GPR_ASSERT(event.tag == nullptr);
/* status is not initialized */
GPR_ASSERT(status == GRPC_STATUS__DO_NOT_USE);
}
@ -664,7 +662,6 @@ static void _test_close_before_client_send(fd_type fdtype) {
g_ctx.cq, grpc_timeout_milliseconds_to_deadline(100), nullptr);
GPR_ASSERT(event.success == 0);
GPR_ASSERT(event.type == GRPC_QUEUE_TIMEOUT);
GPR_ASSERT(event.tag == nullptr);
grpc_slice_unref(details);
grpc_metadata_array_destroy(&initial_metadata_recv);
@ -720,13 +717,11 @@ static void _test_close_before_call_create(fd_type fdtype) {
g_ctx.client_cq, grpc_timeout_milliseconds_to_deadline(100), nullptr);
GPR_ASSERT(event.type == GRPC_QUEUE_TIMEOUT);
GPR_ASSERT(event.success == 0);
GPR_ASSERT(event.tag == nullptr);
event = grpc_completion_queue_next(
g_ctx.cq, grpc_timeout_milliseconds_to_deadline(100), nullptr);
GPR_ASSERT(event.type == GRPC_QUEUE_TIMEOUT);
GPR_ASSERT(event.success == 0);
GPR_ASSERT(event.tag == nullptr);
grpc_call_unref(call);
end_test();

Loading…
Cancel
Save