X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/4a201b7ceece70d2bc461ac48c8b746a36d07243..dbb6a5398ebdb917f1de3acc0d16cd83cd23de71:/examples/gras/mutual_exclusion/simple_token/simple_token.c diff --git a/examples/gras/mutual_exclusion/simple_token/simple_token.c b/examples/gras/mutual_exclusion/simple_token/simple_token.c index 18a8e3f2ee..90d687224c 100644 --- a/examples/gras/mutual_exclusion/simple_token/simple_token.c +++ b/examples/gras/mutual_exclusion/simple_token/simple_token.c @@ -1,8 +1,7 @@ /* stoken - simple/static token ring */ -/* Copyright (c) 2005 Alexandre Colucci. */ -/* Copyright (c) 2005 Martin Quinson. */ -/* All rights reserved. */ +/* Copyright (c) 2006, 2007, 2009, 2010. The SimGrid Team. + * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -25,10 +24,10 @@ int node(int argc, char *argv[]); /* Global private data */ typedef struct { - gras_socket_t sock; /* server socket on which I hear */ + xbt_socket_t sock; /* server socket on which I hear */ int remaining_loop; /* number of loops to do until done */ int create; /* whether I have to create the token */ - gras_socket_t tosuccessor; /* how to connect to the successor on ring */ + xbt_socket_t tosuccessor; /* how to connect to the successor on ring */ double start_time; /* to measure the elapsed time. Only used by the node that creates the token */ } node_data_t; @@ -37,12 +36,9 @@ typedef struct { /* Callback function */ static int node_cb_stoken_handler(gras_msg_cb_ctx_t ctx, void *payload) { - - xbt_ex_t e; - /* 1. Get the payload into the msg variable, and retrieve my caller */ int msg = *(int *) payload; - gras_socket_t expeditor = gras_msg_cb_ctx_from(ctx); + xbt_socket_t expeditor = gras_msg_cb_ctx_from(ctx); /* 2. Retrieve the node's state (globals) */ @@ -58,19 +54,19 @@ static int node_cb_stoken_handler(gras_msg_cb_ctx_t ctx, void *payload) supersteps = 1; } if (globals->create && (!(globals->remaining_loop % supersteps))) { - INFO1("Begin a new loop. Still to do: %d", globals->remaining_loop); + XBT_INFO("Begin a new loop. Still to do: %d", globals->remaining_loop); } else if (!(globals->remaining_loop % supersteps)) { - VERB3("Got token(%d) from %s remaining_loop=%d", - msg, gras_socket_peer_name(expeditor), globals->remaining_loop); + XBT_VERB("Got token(%d) from %s remaining_loop=%d", + msg, xbt_socket_peer_name(expeditor), globals->remaining_loop); } /* 4. If the right shouldn't be stopped yet */ if (globals->remaining_loop > 0) { msg += 1; - DEBUG3("Send token(%d) to %s:%d", msg, - gras_socket_peer_name(globals->tosuccessor), - gras_socket_peer_port(globals->tosuccessor)); + XBT_DEBUG("Send token(%d) to %s:%d", msg, + xbt_socket_peer_name(globals->tosuccessor), + xbt_socket_peer_port(globals->tosuccessor)); /* 5. Send the token as payload of a stoken message to the successor */ TRY { @@ -78,9 +74,9 @@ static int node_cb_stoken_handler(gras_msg_cb_ctx_t ctx, void *payload) /* 6. Deal with errors */ } - CATCH(e) { + CATCH_ANONYMOUS { gras_socket_close(globals->sock); - RETHROW0("Unable to forward token: %s"); + RETHROWF("Unable to forward token: %s"); } } @@ -95,8 +91,8 @@ static int node_cb_stoken_handler(gras_msg_cb_ctx_t ctx, void *payload) /* 8. Repport the hop number to the user at the end */ if (globals->remaining_loop == -1 && globals->create) { double elapsed = gras_os_time() - globals->start_time; - INFO1("Shut down the token-ring. There was %d hops.", msg); - VERB1("Elapsed time: %g", elapsed); + XBT_INFO("Shut down the token-ring. There was %d hops.", msg); + XBT_VERB("Elapsed time: %g", elapsed); } /* 9. Tell GRAS that we consummed this message */ @@ -111,8 +107,6 @@ int node(int argc, char *argv[]) int myport; int peerport; - xbt_ex_t e; - /* 1. Init the GRAS infrastructure and declare my globals */ gras_init(&argc, argv); globals = gras_userdata_new(node_data_t); @@ -135,18 +129,18 @@ int node(int argc, char *argv[]) globals->tosuccessor = NULL; if (!gras_os_getpid() % 100 || gras_if_RL()) - INFO3("Launch node listening on %d (successor on %s:%d)", + XBT_INFO("Launch node listening on %d (successor on %s:%d)", myport, host, peerport); /* 4. Register the known messages. */ - gras_msgtype_declare("stoken", gras_datadesc_by_name("int")); + gras_msgtype_declare("stoken", xbt_datadesc_by_name("int")); /* 5. Create my master socket for listening */ globals->sock = gras_socket_server(myport); gras_os_sleep(1.0); /* Make sure all server sockets are created */ /* 6. Create socket to the successor on the ring */ - DEBUG2("Connect to my successor on %s:%d", host, peerport); + XBT_DEBUG("Connect to my successor on %s:%d", host, peerport); globals->tosuccessor = gras_socket_client(host, peerport); @@ -166,13 +160,14 @@ int node(int argc, char *argv[]) globals->remaining_loop = NBLOOPS - 1; - INFO3("Create the token (with value %d) and send it to %s:%d", + XBT_INFO("Create the token (with value %d) and send it to %s:%d", token, host, peerport); TRY { gras_msg_send(globals->tosuccessor, "stoken", &token); - } CATCH(e) { - RETHROW0("Unable to send the freshly created token: %s"); + } + CATCH_ANONYMOUS { + RETHROWF("Unable to send the freshly created token: %s"); } } @@ -180,7 +175,7 @@ int node(int argc, char *argv[]) while (globals->remaining_loop > (globals->create ? -1 : 0)) { gras_msg_handle(-1); - DEBUG1("looping (remaining_loop=%d)", globals->remaining_loop); + XBT_DEBUG("looping (remaining_loop=%d)", globals->remaining_loop); } gras_os_sleep(1.0); /* FIXME: if the sender quited, receive fail */