X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/0a65b57288514819339d81d30b6dcd0fe98ad45e..5964efeaa53eb62b51b814b67ff413f0593a03a0:/examples/msg/chord/chord.c diff --git a/examples/msg/chord/chord.c b/examples/msg/chord/chord.c index 15d3423466..2bfaa484ec 100644 --- a/examples/msg/chord/chord.c +++ b/examples/msg/chord/chord.c @@ -82,6 +82,7 @@ static int *powers2; // utility functions static void chord_initialize(void); +static void chord_exit(void); static int normalize(int id); static int is_in_interval(int id, int start, int end); static void get_mailbox(int host_id, char* mailbox); @@ -127,6 +128,11 @@ static void chord_initialize(void) XBT_DEBUG("Sets nb_keys to %d", nb_keys); } +static void chord_exit(void) +{ + xbt_free(powers2); +} + /** * \brief Turns an id into an equivalent id in [0, nb_keys). * \param id an id @@ -139,7 +145,7 @@ static int normalize(int id) } /** - * \brief Returns whether a id belongs to the interval [start, end]. + * \brief Returns whether an id belongs to the interval [start, end]. * * The parameters are noramlized to make sure they are between 0 and nb_keys - 1). * 1 belongs to [62, 3] @@ -342,13 +348,16 @@ int node(int argc, char *argv[]) MSG_process_sleep(5); } } - else { + + if (node.comm_receive && MSG_comm_test(node.comm_receive)) { + // a transfer has occured MSG_error_t status = MSG_comm_get_status(node.comm_receive); if (status != MSG_OK) { XBT_DEBUG("Failed to receive a task. Nevermind."); + MSG_comm_destroy(node.comm_receive); node.comm_receive = NULL; } else { @@ -358,35 +367,12 @@ int node(int argc, char *argv[]) handle_task(&node, task_received); } } - - // see if some communications are finished - /* - while ((index = MSG_comm_testany(node.comms)) != -1) { - comm_send = xbt_dynar_get_as(node.comms, index, msg_comm_t); - MSG_error_t status = MSG_comm_get_status(comm_send); - xbt_dynar_remove_at(node.comms, index, &comm_send); - XBT_DEBUG("Communication %p is finished with status %d, dynar size is now %lu", - comm_send, status, xbt_dynar_length(node.comms)); - m_task_t task = MSG_comm_get_task(comm_send); - MSG_comm_destroy(comm_send); - if (status != MSG_OK) { - task_data_destroy(MSG_task_get_data(task)); - MSG_task_destroy(task); - } - } - */ } - // clean unfinished comms sent - /* unsigned int cursor; - xbt_dynar_foreach(node.comms, cursor, comm_send) { - m_task_t task = MSG_comm_get_task(comm_send); - MSG_task_cancel(task); - task_data_destroy(MSG_task_get_data(task)); - MSG_task_destroy(task); - MSG_comm_destroy(comm_send); - // FIXME: the task is actually not destroyed because MSG thinks that the other side (whose process is dead) is still using it - }*/ + if (node.comm_receive) { + MSG_comm_destroy(node.comm_receive); + node.comm_receive = NULL; + } // leave the ring leave(&node); @@ -936,6 +922,7 @@ int main(int argc, char *argv[]) XBT_INFO("Simulated time: %g", MSG_get_clock()); MSG_clean(); + chord_exit(); if (res == MSG_OK) return 0;