From 1e8e558a77e095093de87486d8956c9922d1c36d Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 21 Jun 2016 14:29:11 +0200 Subject: [PATCH] simplify these loops to please sonarqube --- examples/msg/actions-comm/actions-comm.c | 8 +++++--- examples/simdag/availability/sd_availability.c | 12 +++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/examples/msg/actions-comm/actions-comm.c b/examples/msg/actions-comm/actions-comm.c index 0e0219473c..8bcbc17cb7 100644 --- a/examples/msg/actions-comm/actions-comm.c +++ b/examples/msg/actions-comm/actions-comm.c @@ -54,10 +54,12 @@ static void asynchronous_cleanup(void) process_globals_t globals = (process_globals_t) MSG_process_get_data(MSG_process_self()); /* Destroy any isend which correspond to completed communications */ - int found; msg_comm_t comm; - while ((found = MSG_comm_testany(globals->isends)) != -1) { - xbt_dynar_remove_at(globals->isends, found, &comm); + while (1/*true*/) { + int pos_found = MSG_comm_testany(globals->isends); + if (pos_found == -1) /* none remaining */ + break; + xbt_dynar_remove_at(globals->isends, pos_found, &comm); MSG_comm_destroy(comm); } } diff --git a/examples/simdag/availability/sd_availability.c b/examples/simdag/availability/sd_availability.c index 2371c56df6..45f0a1679c 100644 --- a/examples/simdag/availability/sd_availability.c +++ b/examples/simdag/availability/sd_availability.c @@ -39,10 +39,6 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(sd_avail, "Logging specific to this SimDag example" int main(int argc, char **argv) { - unsigned int ctr; - SD_task_t task; - xbt_dynar_t changed_tasks; - SD_init(&argc, argv); SD_create_environment(argv[1]); const sg_host_t *hosts = sg_host_list(); @@ -79,11 +75,17 @@ int main(int argc, char **argv) SD_task_watch(c3, SD_DONE); SD_task_watch(t4, SD_DONE); - while (xbt_dynar_is_empty((changed_tasks = SD_simulate(-1.0))) == 0) { + while (1) { + xbt_dynar_t changed_tasks = SD_simulate(-1.0); + if (xbt_dynar_is_empty(changed_tasks)) + break; XBT_INFO("link1: bw=%.0f, lat=%f", SD_route_get_bandwidth(hosts[0], hosts[1]), SD_route_get_latency(hosts[0], hosts[1])); XBT_INFO("Jupiter: speed=%.0f", sg_host_speed(hosts[0])* sg_host_get_available_speed(hosts[0])); XBT_INFO("Tremblay: speed=%.0f", sg_host_speed(hosts[1])* sg_host_get_available_speed(hosts[1])); + + unsigned int ctr; + SD_task_t task; xbt_dynar_foreach(changed_tasks, ctr, task) { XBT_INFO("Task '%s' start time: %f, finish time: %f", SD_task_get_name(task), SD_task_get_start_time(task), SD_task_get_finish_time(task)); -- 2.30.2