Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
vacation commit
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 24 Oct 2016 08:54:13 +0000 (10:54 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 24 Oct 2016 08:54:13 +0000 (10:54 +0200)
chase some sonar minor smells

15 files changed:
examples/msg/actions-comm/actions-comm.c
examples/msg/app-bittorrent/connection.h
examples/msg/app-chainsend/broadcaster.h
examples/msg/app-chainsend/messages.h
examples/msg/app-chainsend/peer.h
examples/msg/app-pmm/app-pmm.c
examples/msg/cloud-migration/cloud-migration.c
examples/msg/cloud-two-tasks/cloud-two-tasks.c
examples/msg/dht-kademlia/answer.h
examples/msg/dht-kademlia/dht-kademlia.c
examples/msg/dht-kademlia/node.c
examples/msg/dht-kademlia/node.h
examples/msg/dht-kademlia/routing_table.c
examples/msg/dht-kademlia/routing_table.h
examples/msg/dht-kademlia/task.h

index 8bcbc17..b5dcc48 100644 (file)
@@ -19,7 +19,9 @@ typedef struct {
   /* Used to implement irecv+wait */
   xbt_dynar_t irecvs;           /* of msg_comm_t */
   xbt_dynar_t tasks;            /* of msg_task_t */
-} s_process_globals_t, *process_globals_t;
+} s_process_globals_t;
+
+typedef s_process_globals_t *process_globals_t;
 
 /* Helper function */
 static double parse_double(const char *string)
@@ -172,7 +174,8 @@ static void action_barrier(const char *const *action)
   ACT_DEBUG("Entering barrier: %s (%d already there)", NAME, processes_arrived_sofar);
 
   simcall_mutex_lock(mutex);
-  if (++processes_arrived_sofar == communicator_size) {
+  processes_arrived_sofar++;
+  if (processes_arrived_sofar == communicator_size) {
     simcall_cond_broadcast(cond);
     simcall_mutex_unlock(mutex);
   } else {
@@ -203,7 +206,8 @@ static void action_bcast(const char *const *action)
 
   const char * process_name = MSG_process_get_name(MSG_process_self());
 
-  char *bcast_identifier = bprintf("bcast_%d", counters->bcast_counter++);
+  char *bcast_identifier = bprintf("bcast_%d", counters->bcast_counter);
+  counters->bcast_counter++;
 
   if (!strcmp(process_name, "p0")) {
     XBT_DEBUG("%s: %s is the Root", bcast_identifier, process_name);
index 0bfcde0..30e6ba4 100644 (file)
@@ -20,7 +20,9 @@ typedef struct s_connection {
   unsigned int interested:1;      //Indicates if the peer is interested in one of our pieces
   unsigned int choked_upload:1;   //Indicates if the peer is choked for the current peer
   unsigned int choked_download:1; //Indicates if the peer has choked the current peer
-} s_connection_t, *connection_t;
+} s_connection_t;
+
+typedef s_connection_t *connection_t;
 
 /** @brief Build a new connection object from the peer id.
  *  @param id id of the peer
index e9aca94..d4413d4 100644 (file)
@@ -28,7 +28,9 @@ typedef struct s_broadcaster {
   xbt_dynar_iterator_t it;
   int max_pending_sends;
   xbt_dynar_t pending_sends;
-} s_broadcaster_t, *broadcaster_t;
+} s_broadcaster_t;
+
+typedef s_broadcaster_t *broadcaster_t;
 
 xbt_dynar_t build_hostlist_from_hostcount(int hostcount); 
 
index e90bf62..e6855ea 100644 (file)
@@ -27,7 +27,9 @@ typedef struct s_message {
   const char *data_block;
   unsigned int data_length;
   unsigned int num_pieces;
-} s_message_t, *message_t;
+} s_message_t;
+
+typedef s_message_t *message_t;
 
 /* Message methods */
 msg_task_t task_message_new(e_message_type type, unsigned int len);
index 4ed5bcc..5099d1b 100644 (file)
@@ -26,7 +26,8 @@ typedef struct s_peer {
   xbt_dynar_t pending_recvs;
   xbt_dynar_t pending_sends;
   unsigned int total_pieces;
-} s_peer_t, *peer_t;
+} s_peer_t;
+typedef s_peer_t *peer_t;
 
 /* Peer: helper functions */
 msg_error_t peer_wait_for_message(peer_t peer);
index 7ddb867..e68636f 100644 (file)
@@ -20,9 +20,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_pmm, "Messages specific for this msg example");
 #define MAILBOX_NAME_SIZE 10
 #define NEIGHBOURS_COUNT GRID_SIZE - 1
 
-/*
- * The job sent to every node
- */
+/* The job sent to every node */
 typedef struct s_node_job{
   int row;
   int col;
@@ -30,16 +28,18 @@ typedef struct s_node_job{
   int nodes_in_col[NEIGHBOURS_COUNT];
   xbt_matrix_t A;
   xbt_matrix_t B;
-} s_node_job_t, *node_job_t;
+} s_node_job_t;
 
-/*
- * Structure for recovering results
- */
+typedef s_node_job_t *node_job_t;
+
+/* Structure for recovering results */
 typedef struct s_result {
   int row;
   int col;
   xbt_matrix_t sC;
-} s_result_t, *result_t;
+} s_result_t;
+
+typedef s_result_t *result_t;
 
 int node(int argc, char **argv);
 static void create_jobs(xbt_matrix_t A, xbt_matrix_t B, node_job_t *jobs);
@@ -53,7 +53,8 @@ static void task_cleanup(void *arg);
 int node(int argc, char **argv)
 {
   char my_mbox[MAILBOX_NAME_SIZE];
-  node_job_t myjob, jobs[GRID_NUM_NODES];
+  node_job_t myjob;
+  node_job_t jobs[GRID_NUM_NODES];
   xbt_matrix_t A = NULL;
   xbt_matrix_t B = NULL;
   xbt_matrix_t C = NULL;
@@ -274,16 +275,17 @@ static void create_jobs(xbt_matrix_t A, xbt_matrix_t B, node_job_t *jobs)
     jobs[node]->row = row;
     jobs[node]->col = col;
 
-    /* Compute who are the nodes in the same row and column */
-    /* than the node receiving this job */
-    for (int j = 0, k = 0; j < GRID_SIZE; j++) {
+    /* Compute who are the nodes in the same row and column than the node receiving this job */
+    int k=0;
+    for (int j = 0; j < GRID_SIZE; j++) {
       if (node != (GRID_SIZE * row) + j) {
         jobs[node]->nodes_in_row[k] = (GRID_SIZE * row) + j;
         k++;
       }
     }
 
-    for (int j = 0, k = 0; j < GRID_SIZE; j++) {
+    k=0;
+    for (int j = 0; j < GRID_SIZE; j++) {
       if (node != (GRID_SIZE * j) + col) {
         jobs[node]->nodes_in_col[k] = (GRID_SIZE * j) + col;
         k++;
@@ -296,7 +298,8 @@ static void create_jobs(xbt_matrix_t A, xbt_matrix_t B, node_job_t *jobs)
     jobs[node]->B =
       xbt_matrix_new_sub(B, NODE_MATRIX_SIZE, NODE_MATRIX_SIZE, NODE_MATRIX_SIZE * row, NODE_MATRIX_SIZE * col, NULL);
 
-    if (++col >= GRID_SIZE){
+    col++;
+    if (col >= GRID_SIZE){
       col = 0;
       row++;
     }
index 32015e7..32265f5 100644 (file)
@@ -55,11 +55,10 @@ static int master_main(int argc, char *argv[])
   msg_host_t pm0 = MSG_host_by_name("Fafard");
   msg_host_t pm1 = MSG_host_by_name("Tremblay");
   msg_host_t pm2 = MSG_host_by_name("Bourassa");
-  msg_vm_t vm0, vm1;
   s_vm_params_t params;
   memset(&params, 0, sizeof(params));
 
-  vm0 = MSG_vm_create_core(pm0, "VM0");
+  msg_vm_t vm0 = MSG_vm_create_core(pm0, "VM0");
   params.ramsize = 1L * 1000 * 1000 * 1000; // 1Gbytes
   MSG_vm_set_params(vm0, &params);
   MSG_vm_start(vm0);
@@ -80,7 +79,7 @@ static int master_main(int argc, char *argv[])
   MSG_vm_destroy(vm0);
 
   vm0 = MSG_vm_create_core(pm0, "VM0");
-  vm1 = MSG_vm_create_core(pm0, "VM1");
+  msg_vm_t vm1 = MSG_vm_create_core(pm0, "VM1");
 
   params.ramsize = 1L * 1000 * 1000 * 1000; // 1Gbytes
   MSG_vm_set_params(vm0, &params);
index 285a69a..c9afd7c 100644 (file)
@@ -14,12 +14,11 @@ static int computation_fun(int argc, char *argv[])
 {
   const char *pr_name = MSG_process_get_name(MSG_process_self());
   const char *host_name = MSG_host_get_name(MSG_host_self());
-  double clock_sta, clock_end;
   atask = MSG_task_create("Task1", 1e9, 1e9, NULL);
-  clock_sta = MSG_get_clock();
+  double clock_sta = MSG_get_clock();
   XBT_INFO("%s:%s task 1 created %g", host_name, pr_name, clock_sta);
   MSG_task_execute(atask);
-  clock_end = MSG_get_clock();
+  double clock_end = MSG_get_clock();
 
   XBT_INFO("%s:%s task 1 executed %g", host_name, pr_name, clock_end - clock_sta);
 
@@ -57,10 +56,8 @@ static int master_main(int argc, char *argv[])
 {
   xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar();
   msg_host_t pm0 = MSG_host_by_name("Fafard");
-  msg_vm_t vm0;
-  vm0 = MSG_vm_create_core(pm0, "VM0");
+  msg_vm_t   vm0 = MSG_vm_create_core(pm0, "VM0");
   MSG_vm_start(vm0);
-  //MSG_process_sleep(1);
 
   launch_computation_worker(vm0);
 
index 03fe765..e381816 100644 (file)
@@ -14,7 +14,9 @@ typedef struct s_node_answer {
   unsigned int destination_id;
   xbt_dynar_t nodes;            //Dynar of node_contact_t
   unsigned int size;
-} s_answer_t, *answer_t;
+} s_answer_t;
+
+typedef s_answer_t *answer_t;
 
 #include "node.h"
 
index 1b0dc44..ad73ec1 100644 (file)
@@ -112,7 +112,8 @@ unsigned int join(node_t node, unsigned int id_known)
   answer_t node_list;
   msg_error_t status;
   unsigned int trial = 0;
-  unsigned int i, answer_got = 0;
+  unsigned int i;
+  unsigned int answer_got = 0;
 
   /* Add the guy we know to our routing table and ourselves. */
   node_routing_table_update(node, node->id);
@@ -178,11 +179,13 @@ unsigned int join(node_t node, unsigned int id_known)
 unsigned int find_node(node_t node, unsigned int id_to_find, unsigned int count_in_stats)
 {
   unsigned int i = 0;
-  unsigned int queries, answers;
+  unsigned int queries;
+  unsigned int answers;
   unsigned int destination_found = 0;
   unsigned int nodes_added = 0;
   double time_beginreceive;
-  double timeout, global_timeout = MSG_get_clock() + find_node_global_timeout;
+  double timeout;
+  double global_timeout = MSG_get_clock() + find_node_global_timeout;
   unsigned int steps = 0;
 
   xbt_assert((id_to_find >= 0), "Id supplied incorrect");
@@ -358,7 +361,8 @@ void send_find_node(node_t node, unsigned int id, unsigned int destination)
   */
 unsigned int send_find_node_to_best(node_t node, answer_t node_list)
 {
-  unsigned int i = 0, j = 0;
+  unsigned int i = 0;
+  unsigned int j = 0;
   unsigned int destination = node_list->destination_id;
   node_contact_t node_to_query;
   while (j < kademlia_alpha && i < node_list->size) {
index 385d0d6..97a89a2 100644 (file)
@@ -127,8 +127,8 @@ unsigned int get_id_in_prefix(unsigned int id, unsigned int prefix)
   */
 unsigned int get_node_prefix(unsigned int id, unsigned int nb_bits)
 {
-  unsigned int j, size = sizeof(unsigned int) * 8;
-  for (j = 0; j < size; j++) {
+  unsigned int size = sizeof(unsigned int) * 8;
+  for (unsigned int j = 0; j < size; j++) {
     if (((id >> (size - 1 - j)) & 0x1) != 0) {
       return nb_bits - (j);
     }
index b2ff733..0659d7d 100644 (file)
@@ -17,7 +17,9 @@
 typedef struct s_node_contact {
   unsigned int id;              //The node identifier
   unsigned int distance;        //The distance from the node
-} s_node_contact_t, *node_contact_t;
+} s_node_contact_t;
+
+typedef s_node_contact_t *node_contact_t;
 
 /* Node data */
 typedef struct s_node {
@@ -30,7 +32,9 @@ typedef struct s_node {
   unsigned int find_node_success;       //Number of find_node which have succeeded.
   unsigned int find_node_failed;        //Number of find_node which have failed.
 
-} s_node_t, *node_t;
+} s_node_t;
+
+typedef s_node_t *node_t;
 
 // node functions
 node_t node_init(unsigned int id);
index 20757af..d39741e 100644 (file)
@@ -13,10 +13,9 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_kademlia_routing_table, "Messages specific for
 /** @brief Initialization of a node routing table.  */
 routing_table_t routing_table_init(unsigned int node_id)
 {
-  unsigned int i;
   routing_table_t table = xbt_new(s_routing_table_t, 1);
   table->buckets = xbt_new(s_bucket_t, identifier_size + 1);
-  for (i = 0; i < identifier_size + 1; i++) {
+  for (unsigned int i = 0; i < identifier_size + 1; i++) {
     table->buckets[i].nodes = xbt_dynar_new(sizeof(unsigned int), NULL);
     table->buckets[i].id = i;
   }
@@ -46,10 +45,11 @@ unsigned int routing_table_contains(routing_table_t table, unsigned int node_id)
 /**@brief prints the routing table, to debug stuff. */
 void routing_table_print(routing_table_t table)
 {
-  unsigned int i, j, value;
+  unsigned int j;
+  unsigned int value;
   XBT_INFO("Routing table of %08x:", table->id);
 
-  for (i = 0; i <= identifier_size; i++) {
+  for (unsigned int i = 0; i <= identifier_size; i++) {
     if (!xbt_dynar_is_empty(table->buckets[i].nodes)) {
       XBT_INFO("Bucket number %d: ", i);
       xbt_dynar_foreach(table->buckets[i].nodes, j, value) {
@@ -65,7 +65,8 @@ void routing_table_print(routing_table_t table)
   */
 unsigned int bucket_find_id(bucket_t bucket, unsigned int id)
 {
-  unsigned int i, current_id;
+  unsigned int i;
+  unsigned int current_id;
   xbt_dynar_foreach(bucket->nodes, i, current_id){
     if (id == current_id){
       return i;
index 63ae7b5..388f595 100644 (file)
 typedef struct s_bucket {
   xbt_dynar_t nodes;            //Nodes in the bucket.
   unsigned int id;              //bucket id
-} s_bucket_t, *bucket_t;
+} s_bucket_t;
+
+typedef s_bucket_t *bucket_t;
 
 /* Node routing table */
 typedef struct s_routing_table {
   unsigned int id;              //node id of the client's routing table
   s_bucket_t *buckets;          //Node bucket list - 160 sized.
-} s_routing_table_t, *routing_table_t;
+} s_routing_table_t;
+
+typedef s_routing_table_t *routing_table_t;
 
 // bucket functions
 unsigned int bucket_find_id(bucket_t bucket, unsigned int id);
index a7cd143..cca5e29 100644 (file)
@@ -29,7 +29,9 @@ typedef struct s_task_data {
   answer_t answer;              //Answer to the request made, if needed.
   char *answer_to;              // mailbox to send the answer to (if not an answer).
   const char *issuer_host_name; // used for logging
-} s_task_data_t, *task_data_t;
+} s_task_data_t;
+
+typedef s_task_data_t *task_data_t;
 
 //Task handling functions
 msg_task_t task_new_find_node(unsigned int sender_id, unsigned int destination_id, char *mailbox, const char *hostname);