X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/2adbebb21ea989090627ef4062f99c6ae19b32f5..dcbef682c82dc36f62828f331ba4adc39d0324ea:/examples/msg/chord/chord.c diff --git a/examples/msg/chord/chord.c b/examples/msg/chord/chord.c index e2aa9d0310..8dafba417c 100644 --- a/examples/msg/chord/chord.c +++ b/examples/msg/chord/chord.c @@ -1,5 +1,4 @@ - -/* Copyright (c) 2010. The SimGrid Team. +/* Copyright (c) 2010-2014. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -38,6 +37,8 @@ static int periodic_fix_fingers_delay = 120; static int periodic_check_predecessor_delay = 120; static int periodic_lookup_delay = 10; +static const double sleep_delay = 4.9999; + extern long int smx_total_comms; /* @@ -293,11 +294,9 @@ int node(int argc, char *argv[]) double next_check_predecessor_date = init_time + periodic_check_predecessor_delay; double next_lookup_date = init_time + periodic_lookup_delay; - #ifdef HAVE_MC int listen = 0; int no_op = 0; int sub_protocol = 0; - #endif xbt_assert(argc == 3 || argc == 5, "Wrong number of arguments for this node"); @@ -351,7 +350,6 @@ int node(int argc, char *argv[]) // no task was received: make some periodic calls -#ifdef HAVE_MC if(MC_is_active()){ if(!MC_visited_reduction() && no_op){ MC_cut(); @@ -367,7 +365,7 @@ int node(int argc, char *argv[]) random_lookup(&node); listen = 1; }else{ - MSG_process_sleep(5); + MSG_process_sleep(sleep_delay); if(!MC_visited_reduction()) no_op = 1; } @@ -386,27 +384,9 @@ int node(int argc, char *argv[]) next_lookup_date = MSG_get_clock() + periodic_lookup_delay; }else { // nothing to do: sleep for a while - MSG_process_sleep(5); + MSG_process_sleep(sleep_delay); } } -#else - if (MSG_get_clock() >= next_stabilize_date) { - stabilize(&node); - next_stabilize_date = MSG_get_clock() + periodic_stabilize_delay; - }else if (MSG_get_clock() >= next_fix_fingers_date) { - fix_fingers(&node); - next_fix_fingers_date = MSG_get_clock() + periodic_fix_fingers_delay; - }else if (MSG_get_clock() >= next_check_predecessor_date) { - check_predecessor(&node); - next_check_predecessor_date = MSG_get_clock() + periodic_check_predecessor_delay; - }else if (MSG_get_clock() >= next_lookup_date) { - random_lookup(&node); - next_lookup_date = MSG_get_clock() + periodic_lookup_delay; - }else { - // nothing to do: sleep for a while - MSG_process_sleep(5); - } -#endif } else { // a transfer has occurred @@ -428,6 +408,9 @@ int node(int argc, char *argv[]) } if (node.comm_receive) { + /* handle last task if any */ + if (MSG_comm_wait(node.comm_receive, 0) == MSG_OK) + task_free(task_received); MSG_comm_destroy(node.comm_receive); node.comm_receive = NULL; } @@ -535,6 +518,8 @@ static void handle_task(node_t node, msg_task_t task) { MSG_task_dsend(task, task_data->answer_to, task_free); break; + default: + THROW_IMPOSSIBLE; } } @@ -608,7 +593,12 @@ static void quit_notify(node_t node) msg_task_t task_sent = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, req_data); XBT_DEBUG("Sending a 'PREDECESSOR_LEAVING' to my successor %d",node->fingers[0].id); - MSG_task_send_with_timeout(task_sent, node->fingers[0].mailbox, timeout); + if (MSG_task_send_with_timeout(task_sent, node->fingers[0].mailbox, timeout)== + MSG_TIMEOUT) { + XBT_DEBUG("Timeout expired when sending a 'PREDECESSOR_LEAVING' to my successor %d", + node->fingers[0].id); + task_free(task_sent); + } //send the SUCCESSOR_LEAVING to our predecessor get_mailbox(node->pred_id, mailbox); @@ -621,7 +611,12 @@ static void quit_notify(node_t node) msg_task_t task_sent_s = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, req_data_s); XBT_DEBUG("Sending a 'SUCCESSOR_LEAVING' to my predecessor %d",node->pred_id); - MSG_task_send_with_timeout(task_sent_s, mailbox, timeout); + if (MSG_task_send_with_timeout(task_sent_s, mailbox, timeout)== + MSG_TIMEOUT) { + XBT_DEBUG("Timeout expired when sending a 'SUCCESSOR_LEAVING' to my predecessor %d", + node->pred_id); + task_free(task_sent_s); + } }